#include <iostream> #include <fstream> #include <algorithm> #include <stdio.h> #include <string> #include <math.h> #include <vector> #include <queue> #define pb push_back #define lm 510 using namespace std; int a[510][510]; string s; int n,m,res,x,y; int main() { //freopen("cmlsc.in","r",stdin); cin>>n>>m; for(int i=1; i<=n; i++) { cin>>s; for(int j=0; j<m; j++) { if(s[j]=='1') a[i][j+1]=1; } } for(int i=1; i<=m; i++) { for(int j=2; j<=n; j++) { if(a[j-1][i] && a[j][i]) a[j][i]+=a[j-1][i]; //cout<<a[j][i]<<' '; } //cout<<'\n'; } for(int i=2; i<=n; i++) { bool ok=false; for(int j=1; j<=m; j++) { if(ok && a[i][j]) { if(a[i][j]>1) { res=max(res,x+y+a[i][j]); x++; } if(a[i][j]>y+x) { x--; y=a[i][j]; } } else{ if(a[i][j]>1) { x=0; y=a[i][j]; ok=true; } else { ok=false; x=0; } } } } cout<<res; return 0; }