#include using namespace std; long n,m,i,j,mat[505][505],D[505][505],R[505][505],U[505][505],mx; char s[505]; int main() { cin>>n>>m; for (i=1;i<=n;i++) { cin>>s+1; for (j=1;j<=m;j++) mat[i][j]=s[j]-'0'; } for (i=1;i<=n;i++) for (j=1;j<=m;j++) { if (mat[i][j]==1) { D[i][j]=D[i-1][j]+1; if (R[i][j-1]!=0) R[i][j]=R[i][j-1]+1; if (D[i][j-1]>1 && D[i][j-1]+1>R[i][j]) R[i][j]=D[i][j-1]+1; } else D[i][j]=U[i][j]=R[i][j]=0; } for (i=n;i>=1;i--) for (j=1;j<=m;j++) { if (mat[i][j]==1) { if (U[i+1][j]!=0) U[i][j]=U[i+1][j]+1; if (R[i+1][j]>1 && R[i+1][j]+1>U[i][j]) U[i][j]=R[i+1][j]+1; if (U[i][j]>mx) mx=U[i][j]; } } cout<