eolymp
bolt
Try our new interface for solving problems
Problems

Maximal square

Maximal square

Matrix of size n × m is given, consisting of only zeros and ones. Find the largest square submatrix that contains on its sides ones only.

Input

First line contains two integers n and m (1n, m1500). Each of the next n lines contains m digits 0 and 1 space separated. If there is no such squares, print 0.

Output

Print one integer – the size of maximal square that contains on its sides ones only.

Time limit 1 second
Memory limit 122.17 MiB
Input example #1
4 5
01111
01011
11001
11111
Output example #1
4
Input example #2
2 3
000
000
Output example #2
0
Input example #3
3 3
011
011
010
Output example #3
2
Source 2014 Казахстан, 4-й этап Республиканской олимпиады по информатике, Усть-Каменогорск, Март, Задача C