In a bingo game, the host calls numbers one by one, and each player looks for those numbers on their own board.
Each player has an N by N board containing every integer from 1 through N^2 exactly once.
Whenever the host calls a number, the player considers the most recent N called numbers. If some row of the board contains exactly those N numbers in exactly the same order, the player earns 1 point for that row.
Suppose N is 3 and a player has the following board.
| 1 | 3 | 7 |
| 6 | 4 | 5 |
| 2 | 8 | 9 |
Donghyuk always finishes last in bingo. Determined to win today, he has obtained the full order in which the host will call the numbers. Given that order, compute the maximum score he can earn by arranging the numbers on his board optimally.
The first line contains the board size N and the number B of calls the host will make. (2 <= N <= 4, 1 <= B <= 10000)
Each of the next B lines contains one called number, in order. Every number is at least 1 and at most N^2.
Print the maximum score that can be earned.