#include<bits/stdc++.h>
using namespace std;
ifstream fi("BONHOA.inp");
ofstream fo("BONHOA.out");
int m,n,maxp=0,maxs=0,v[4]={0,0,1,-1},h[4]={1,-1,0,0},a[101][101]={0},p=0,s=0;;

int loang(int x,int y){
   a[x][y]=-1; ++s;

   for(int i=0;i<4;++i)if(a[x+v[i]][y+h[i]]==0)++p;

   for(int i=0;i<4;++i)if(a[x+v[i]][y+h[i]]==1)loang(x+v[i],y+h[i]);

   return 0;
}

int main(){
  ios::sync_with_stdio(false);
  int m,n;
  fi>>m>>n;
  for(int i=1;i<=m;++i)
    for(int j=1;j<=n;++j)fi>>a[i][j];

   for(int i=1;i<=m;++i)
    for(int j=1;j<=n;++j){
       p=0,s=0;
       if(a[i][j]==1)loang(i,j);
       maxp=max(maxp,p);
       maxs=max(maxs,s);
    }
fo<<maxs<<endl<<maxp;
}
