Problem list
Log in
#coci00006 · COCI 2006/2007 Contest 1

Debug

Platinum IV 0.6 s 32 MB

While debugging a program, Mirko noticed that a bug may be linked with the existence of so-called square killers in the program memory. The program memory is a matrix of $R$ rows and $C$ columns consisting only of zeroes and ones. A square killer is a square submatrix, consisting of more than one character, that looks exactly the same when rotated $180$ degrees.

For example, the following matrix contains $3$ square killers, of sizes $3$, $2$ and $2$:

101010
111001
101001

Mirko is wondering if there is a connection between the size of the largest square killer and the bug. Help Mirko by writing a program that, given the layout of the memory, outputs the size of the largest square killer. The size of a square killer is the number of rows (equivalently, columns) it consists of.

Input

The first line contains two integers $R$ and $C$, both smaller than or equal to $100$.

The next $R$ lines each contain $C$ characters (0 or 1) with no spaces.

Output

Output the size of the largest square killer on a single line, or output -1 if there are no square killers.

Example 1

Input
3 6
101010
111001
101001
Output
3

Example 2

Input
4 5
10010
01010
10101
01001
Output
3

Example 3

Input
3 3
101
111
100
Output
-1
Source
COCI 2006/2007 Contest 1
Appears in
Not part of a ladder, contest or set yet.
Accepted 1 Submissions 6 Acceptance 100% Solvers 1

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code