#P1282. 庆典的日期
庆典的日期
Description
The Gustil civilization once thrived on Earth about one billion years ago, and its development level in aspects such as calendars, mathematics, and astronomy had already surpassed that of modern times. In numerous temples of the ancient city, archaeologists have discovered a peculiar kind of building, which contains a row of independent rooms.
Here is the internal structure of a relatively small - scale building, which includes 9 rooms:

In the center of each room, there is a turntable. Each turntable is divided into 6 grids, and each grid has a number from 1 to 9 written on it. The turntable can rotate counter - clockwise. The red mark on the turntable always points to the upper grid. The turntables in each room are all different.
The CC Archaeological Studio has recently successfully deciphered the characters of that time, making an important contribution to the further study of the Gustil civilization. First of all, the researchers translated the religious books of that time and learned about the purpose of the building. It turns out that each temple had to hold a large - scale celebration every few years after its completion. Since "the secret of heaven must not be revealed", the temple side does not directly state the date of the celebration, but uses the method of "hinting". The peculiar building was specially constructed to determine the date of the celebration.
The rooms are numbered from 1 to n from left to right. At the same time, there are n priests in the temple, also numbered from 1 to n. These priests pray in the rooms once a year. In the year the temple was built, the priest prays in the room with the same number as his own. At the same time, the number in the grid indicated by the red mark on the turntable is the room number where the priest will pray in the next year. After the priest finishes praying, the turntable is rotated counter - clockwise by one grid. The design of the turntable ensures that there is only one priest in each room during the annual prayer.
Since the temple was built, when, in a certain year during the prayer, the number of each priest is the same as the number of the room where he prays, that is the date of the celebration. In fact, there will be a celebration every few years.
As the chief software consultant of the CC Archaeological Studio, you are responsible for programming to find out the exact date of the first celebration.
Input
The first line of the file contains two integers, n and p. n represents the number of rooms (that is, the number of priests), and p represents the number of grids that the turntable contains. (0 < n, p <= 200)
The following n lines each contain p integers, representing the numbers on the grids of the turntable in each room. The first number in each line represents the number pointed to by the red mark when the temple was built, and the following numbers are given in the clockwise direction.
Output
Only one line, indicating how many years after the temple was built the first celebration is held. If the situation that meets the conditions never occurs or the first year that meets the conditions exceeds 10^9 (by then the Gustil civilization has already declined), then output 'No one knows.'
Input 1
6 3
2 6 3
1 1 1
4 4 6
6 3 5
3 2 2
5 5 4
Output 1
18
Source
Chen Hong, Affiliated High School of Fujian Normal University