CCDEBUG - DEBUG

no tags 

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

 

Memory Killer

 

Mirko is wondering if there is a connection between the size of the largest square killer and the bug in the program. Help Mirko by writing a program that, given the layout of the memory, outputs the size of the largest square killer. The size of the square killer is the number of rows (or columns) that the killer consists of. In the example above the killer sizes are 2, 2 and 3, respectively. 

Input

The first will contain two integers, R and C, smaller than or equal to 300. The next R lines will each contain C characters ('0' or '1') with no spaces.

Output

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

Example

Input1:
3 6
101010
111001
101001 Output1: 3
Input2:
4 5
10010
01010
10101
01001
Output2:
3
Input3:
3 3
101
111
100
Output3:
-1



Added by:Hacker7
Date:2014-04-20
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ASM32-GCC MAWK BC C-CLANG C NCSHARP CSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JAVA JS-MONKEY JULIA KTLN NIM OBJC OBJC-CLANG OCT PAS-GPC PAS-FPC PICO PROLOG PYPY PYPY3 R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET
Resource:CROATIAN OPEN COMPETITION IN INFORMATICS 2006/2007 CONTEST 1