Diagonal Flipping
시간 제한1초메모리 제한2048 MB
0과 1로 이루어진 격자가 주어질 때, 두 방향의 대각선 뒤집기를 최소 몇 번 해야 모든 칸을 0으로 만들 수 있는지 구하고, 불가능하면 -1을 출력합니다.
문제
We are given an grid that consists of s and s. We have two types of diagonal operations like the following two figures. The type diagonal flipping operation to a grid position is to flip all the elements in the positions of the grid for any integer . If we flip the element , then it becomes . If we flip the element , then it becomes . The type diagonal flipping operation to a grid position is to flip all the elements in the positions of the grid for any integer . Note that a grid position is valid only when , .

Fig 1. Type diagonal operation to the grid position

Fig 2. Type diagonal operation to the grid position
Fig 1 shows the type diagonal flipping operation to the grid position . Note that the type diagonal flipping operations to the grid positions or have the same effect. Fig 2 shows the type diagonal flipping operation to the grid position . The type diagonal flipping operations to the grid positions or have the same effect.
Given an information of an grid, write a program to output the minimum number of the diagonal operations to make all the elements in the grid to zeros.
입력
Your program is to read from standard input. The first line of input contains two positive integers () and () where and indicate the number of rows and columns of the grid, respectively. The rows of the grid are numbered from to and the columns are numbered from to . In the following lines, the -th line contains numbers, separated by spaces, which are zero or one that correspond to the row of the grid.
출력
Your program is to write to standard output. Print exactly one line. The line should contain the minimum number of the diagonal operations to make all the elements of the grid to zeros. If it is not possible to make all the elements of the grid zeros, the program should print the number -1.