Byteasar wants to play a game of checkers, but he cannot find his chessboard. All he found is a wooden board of size n×m, divided into nm equally sized square fields. Each field is painted white or black, and the colours are not necessarily arranged in a proper chessboard pattern.
Byteasar decided to put his carpentry experience to use and cut a chessboard out of the wood with a saw. A chessboard here is a square built from square fields in which every two fields sharing a side have different colours. A 1×1 square has no pair of fields sharing a side, so it counts as a chessboard too.
The board might not contain a square of the size he wants. So he decided to cut out two triangular pieces and glue them together into a chessboard. The two pieces must not overlap, but he may turn them around in any way after cutting them out.
A piece is cut like this. Pick a square area of the board with side k fields and saw along one of its diagonals. The two legs of the resulting triangle run along field boundaries and the hypotenuse runs through field corners, so every field the hypotenuse crosses is split into two halves. Gluing two such pieces along their hypotenuses gives a k×k square. Two halves that meet on the hypotenuse become one field of the finished square, so they must have the same colour.
The two pieces must not overlap. Two different pieces each taking one half of a field the saw passed through does not count as overlapping. The figure below shows a board of size 4×5 and two triangles that glue together into a chessboard of size 3×3.

Find the largest chessboard size Byteasar can obtain this way.
The first line contains two integers n and m, the size of the board (1≤n,m≤1000).
Each of the next n lines contains m integers. The j-th number in the i-th line is the colour of the field where row i meets column j, where 0 is a white field and 1 is a black field (1≤i≤n, 1≤j≤m).
Print one integer, the number of fields along one side of the largest chessboard that can be made by cutting out two triangular pieces and gluing them together.