For the Christmas holidays, you were gifted a binary matrix of size n \cdot m.
You can perform the following operations on it:
Invert the values of all elements in row .
Invert the values of all elements in column .
A matrix is called good if the following condition holds for all values of and :
A_{i, j} = A_{n-i+1, m-j+1}
You want to make your matrix good with the least possible number of operations.
The first line contains two integers and (1 \le n, m \le 5000) — the dimensions of matrix . The next lines contain numbers a_{i,j} (0 \le a_{i,j} \le 1) — the values of matrix .
Output a single integer — the minimum number of operations.
If there is no solution, output .
Example 1
Example 2
Example 3
To the second test:
We can perform the following transformations:
\begin{smallmatrix} 1 & 0 & 1 & 0 & 0 \\ 0 & 1 & 1 & 0 & 1 \\ 1 & 1 & 1 & 0 & 1 \\ 0 & 0 & 0 & 1 & 1 \\ 0 & 1 & 1 & 1 & 1 \end{smallmatrix} \begin{smallmatrix} 1 & 1 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0 & 1 \\ 0 & 1 & 0 & 1 & 1 \\ 0 & 0 & 1 & 1 & 1 \end{smallmatrix} by inverting column 2
\begin{smallmatrix} 1 & 1 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0 & 1 \\ 0 & 1 & 0 & 1 & 1 \\ 0 & 0 & 1 & 1 & 1 \end{smallmatrix} \begin{smallmatrix} 1 & 1 & 1 & 0 & 0 \\ 1 & 1 & 0 & 1 & 0 \\ 1 & 0 & 1 & 0 & 1 \\ 0 & 1 & 0 & 1 & 1 \\ 0 & 0 & 1 & 1 & 1 \end{smallmatrix} by inverting row 2.
For the matrix \begin{smallmatrix} 1 & 1 & 1 & 0 & 0 \\ 1 & 1 & 0 & 1 & 0 \\ 1 & 0 & 1 & 0 & 1 \\ 0 & 1 & 0 & 1 & 1 \\ 0 & 0 & 1 & 1 & 1 \end{smallmatrix} , the condition of beauty holds. It can be proven that this is the minimum answer.
Subtask ( points): (n, m \le 10)
Subtask ( points): (n = 1)
Subtask ( points): (n, m \le 100)
Subtask ( points): (n, m \le 500)
Subtask ( points): No additional constraints