You play a game with your friend. He draws several lines on the paper with n×m square grids (see the left figure). After that, he writes down the number of lines passing through every integer coordinate in a matrix (see the right figure).
The number of lines passing though coordinate (i,j) is written in cell (i,j) in the right figure.(i,j both start from 0).
You are given the matrix written by your friend. You need to figure out the possible minimal number of lines your friend drew on the paper.