Gift#12321

Gift

15 seconds
256 megabytes
Hard

For the Christmas holidays, you were gifted a binary matrix of size n \cdot m.

You can perform the following operations on it:

  1. Invert the values of all elements in row .

  2. 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.

Input

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

Output a single integer — the minimum number of operations.

If there is no solution, output .

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading

Example 3

Loading
Loading

Note

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.

Scoring

  1. Subtask ( points): (n, m \le 10)

  2. Subtask ( points): (n = 1)

  3. Subtask ( points): (n, m \le 100)

  4. Subtask ( points): (n, m \le 500)

  5. Subtask ( points): No additional constraints