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 (1 ≤ n, m ≤ 1500). 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.
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