#include<iostream>
#include<utility>
using namespace std;
typedef long long ll;
#define fi(i,a,b) for(int i = a; i <= b; ++i)
#define fr(i,a,b) for(int i = a; i >= b; --i)
#define x first
#define y second
#define sz(x) ((int)(x).size())
#define pb push_back
using pii = pair<int,int>;
//#define DEBUG
int dp[105][105];
int matrix[105][105];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin >> n >> m;
fi(i,1,n) fi(j,1,m) cin >> matrix[i][j];
fi(i,1,n) fi(j,1,m){
int s = min(min(dp[i][j-1],dp[i-1][j]),dp[i-1][j-1]);
if(matrix[i][j] == 1){
dp[i][j] = s + 1;
}
}
int maxx = 0;
fi(i,1,n) fi(j,1,m) maxx = max(maxx,dp[i][j]);
cout << maxx << endl;
#ifdef DEBUG
//freopen(D:\in.txt,r,stdin);
#endif
return 0;
}