**
3 8 7 9 1 6 4 1 5 **

2 1 6 3 8 7 3 6 6

5 9 4 2 4 5 2 8 7

4 6 7 1 4 9 8 2 3

9 2 1 7 5 2 1 7 8

8 7 3 1 3 9 6 8 3

6 9 4 5 6 7 2 7 1

5 1 8 7 2 3 1 6 3

3 7 2 6 1 2 8 2 5

The above 9*9 matrix was not generated randomly.

There was some principle in its creation - for you to discover.

So what is it??

At a party with N people, each person is identified by a unique number between 1 and N. Each person is also wearing a hat with their number on it. They decide to play a game. Each person passes his or her hat to the person with the next highest number (so person 2 gets hat 1, person 3 gets hat 2, and person 1 gets hat N). The game proceeds from there in rounds; on each round, each person may choose to either keep the hat they currently have, or swap hats with exactly one other person.

What is the minimum number of rounds, as a function of N, that it would take for every person to get their own hat back? Note: each person can see their own hat at any time.