#define _CRT_SECURE_NO_DEPRECATE #define _USE_MATH_DEFINES #include /* */ using namespace std ; typedef long long LL ; typedef unsigned long long ULL ; typedef unsigned int uint; typedef unsigned char uchar; typedef vector vi ; typedef vector vvi ; typedef vector vs ; typedef vector vvs ; typedef pair pss ; typedef pair pdd; typedef pair pii ; typedef pair pll ; typedef pair puu; #define all(V) (V).begin(), (V).end() #define allr(V) (V).rbegin(), (V).rend() #define SET(Adr,val) memset(Adr,val,sizeof(Adr)) #define SET0(Adr) memset(Adr,0,sizeof(Adr)) #define CMP(Adr1,Adr2) memcmp(&Adr1,&Adr2,sizeof(Adr1)) #define FOR(it,a,b) for( int(it) = (int)a ; it<= (int(b)) ; ++it ) #define FORN(it,a,b) for( int(it) = (int)a ; it< (int(b)) ; ++it ) #define FORV(it,v) for( it = (v).begin() ; it!=(v).end() ; ++it ) #define FORMI(i,j,ii,jj,im,jm) for( int(i) = (int)ii ; i < (int)im ; ++i )\ for( int(j) = (int)jj ; j < (int)jm ; ++j ) #define FORMO(i,j,ii,jj,im,jm) for( int(i) = (int)ii ; i < (int)im ; ++i, cout << '\n')\ for( int(j) = (int)jj ; j < (int)jm ; ++j, cout << ' ' ) #define SHOWME(x) cerr << __LINE__ << ": " << #x << " = " << (x) <<'\n'; #define inchide cerr << "\nLine "<< __LINE__ << " just passed...EXIT\n" ;exit(-1); #define Cat(a,b) ((double(a))/(double(b))) #define Min(a,b) (((a)>(b))?(b):(a)) #define Max(a,b) (((a)>(b))?(a):(b)) #define Prod(a,b) (((a)*(b))) #define Pow2(a) (((a)*(a))) #define sz(x) ((int)(x).size()) #define forn(i,n) for(int i=0;i<(n);++i) #define fors(i,v) forn(i,sz(v)) #define MOD1 1000000007 #define NMAX 10000 #define NMAX2 20001 #define mp make_pair #define pb push_back #define fi first #define se second #define left asdleft #define right asdright #define link asdlink #define unlink asdunlink #define next asdnext #define prev asdprev const double Euler = 2.71828182845904523536 ; const double PI = 3.14159265358979323846 ; const double EPS = 1e-10; const int INF = 0x3fefefef ; const double DINF = 1e200; const LL LINF = INF*1ll*INF; const int dx[4] = { 0 ,-1 , 0 ,1 } ; const int dy[4] = { 1 , 0 ,-1 ,0 } ; /* |V1| |E3| |SV5| |SE7| */ const int dx8[8] = { 0 ,-1 ,0 ,1 ,1 ,-1 ,-1 , 1 } ; const int dy8[8] = { 1 , 0 ,-1 ,0 ,1 ,-1 , 1 ,-1 } ; /* |N0| |S2| |NE4| |NV6| */ template inline ostream& operator<<(ostream &out,const pair&__p) {return(out<<__p.fi<<' '<<__p.se<<'\n');} template inline istream& operator>>(istream &in,pair&__p) {in>>__p.fi>>__p.se;return(in);} template inline ostream& operator<<(ostream &out ,const pair&__p){ (out<<__p.fi<<' '<<__p.se<< '\n');} template inline istream& operator>>(istream &in ,pair&__p){ in>>__p.fi>>__p.se;return(in);} inline int toint(const string &s){istringstream iss(s);int res;iss>>res;return(res);} inline double dist2pct(int _x,int _y,int _z,int _w){return(sqrt(Pow2(_z-_x)+Pow2(_w-_y)));} templateinline string tostr(const T &x){ostringstream ss;ss<inline ostream& arata(ostream &out ,const T &a){return(out<inline istream& citeste(istream &in ,T &a){return(in>>a);} templatevoid AddNr(T &a, T b){a=a+b;while(a>=MOD1)a-=MOD1;while(a<0)a+=MOD1;} templatevoid ReadNo(T&__no){T __sign=1;char ch;__no=0; while(!isdigit(ch=getchar()))(ch=='-')&&(__sign=-1); do{__no=(__no<<1)+(__no<<3)+(ch-48);}while(isdigit(ch=getchar()));__no*=__sign;} templatestruct Functor{T __A,__B ; inline bool operator() (T __A , T __B ){return (__A >__B) ;}}; /******************************************************************************************/ #define DIM 512 int n , m ; int M[DIM][DIM] ; int A[DIM][DIM] , UP[DIM][DIM] , LU[DIM][DIM] ; void Citire() { // FILE * f = fopen("file.in" , "r"); fscanf(stdin,"%d%d",&n,&m); fgetc(stdin); char line[256] ; FOR( i, 1, n ) { fgets(line+1,sizeof(line) ,stdin); FOR( j, 1, m ) A[i][j] = (line[j]- '0'); } // fclose(f); } /******************************************************************************************/ /** MAIN **/ int main(){ Citire(); FOR ( i , 1 , n ) FOR ( j , 1 , m ) if (A[i][j]) { UP[i][j] = UP[i-1][j] + 1 ; if (!A[i - 1][j]) UP[i][j] = 0; else if (!UP[i - 1][j]) ++UP[i][j]; if (LU[i][j - 1]) LU[i][j] = LU[i][j - 1] + 1; if (UP[i][j - 1]) LU[i][j] = max (LU[i][j], UP[i][j - 1] + 1); } int a = 0 , s = -1 ; FOR ( i , 1 , n ) FOR ( j , 1 , m ) if ( LU[i][j] && UP[i][j] ) { a = LU[i][j] + UP[i][j] - 1 ; if ( a > s )s = a ; } printf("%d\n" ,((s<4) ? 0 : s ) ); return(0); } /** MAIN **/