#P1720E. Misha and Paintings
Misha and Paintings
No submission language available for this problem.
Description
Misha has a square matrix, where the number in row and column is equal to . Misha wants to modify the matrix to contain exactly distinct integers. To achieve this goal, Misha can perform the following operation zero or more times:
- choose any square submatrix of the matrix (you choose , , such that , , , then submatrix is a set of cells with coordinates , such that , ),
- choose an integer , where ,
- replace all integers in the submatrix with .
Please find the minimum number of operations that Misha needs to achieve his goal.
The first input line contains two integers and () — the size of the matrix and the desired amount of distinct elements in the matrix.
Then lines follows. The -th of them contains integers () — the elements of the -th row of the matrix.
Output one integer — the minimum number of operations required.
Input
The first input line contains two integers and () — the size of the matrix and the desired amount of distinct elements in the matrix.
Then lines follows. The -th of them contains integers () — the elements of the -th row of the matrix.
Output
Output one integer — the minimum number of operations required.
Samples
Note
In the first test case the answer is , because one can change the value in the bottom right corner of the matrix to . The resulting matrix can be found below:
1 | 1 | 1 |
1 | 1 | 2 |
3 | 4 | 1 |
In the second test case the answer is . First, one can change the entire matrix to contain only s, and the change the value of any single cell to . One of the possible resulting matrices is displayed below:
1 | 1 | 1 |
1 | 1 | 1 |
1 | 1 | 2 |