BINGO
문제
In a simplified version of the popular game of Bingo, the host reads numbers and each player looks for those numbers on his card.
Each player has a card which contains all the numbers from 1 to N2 in N rows and N columns.
The host reads the numbers and the players check if the last N numbers read match one of the rows on their card. Numbers on the card have to be in the same order as the read numbers. The player gets 1point for each match.
For example, suppose N is 3 and the player has the following card:
| 1 | 3 | 7 |
| 6 | 4 | 5 |
| 2 | 8 | 9 |
If the host reads the following numbers: 7, 1, 3, 6, 4, 5, 7, 1, 2, 2, 8, 9, 3, then the player gets 2 points, because sequences 6, 4, 5 and 2, 8, 9 appear as rows on his card.
Disappointed with his card for which he got a small number of points, Mirko wonders what is the largest possible number of points he could get if the same numbers are read, considering all possible cards.
입력
The first line contains two integers N and B (2 ≤ N ≤ 4, 1 ≤ B ≤ 10 000), the size of the card and the number of numbers which the host reads.
The following B lines contain numbers which the host has read. Each of those numbers will be between 1 and N2.
출력
Output the largest number of points over all possible cards.
힌트
Clarification for first example: one of those cards has 1 2 (contributes 4 points) and 3 4 (1 point) in its rows.
예제
예제 1
2 11 1 2 1 2 1 2 1 2 3 4 1
5
예제 2
3 14 1 1 1 1 1 2 3 4 5 6 8 9 9 9
2