#include <bits/stdc++.h>
#define endl cout<<"\n";
#define fi first
#define int long long
#define se second
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define op freopen
#define TXT "test"
#define freo if(fopen(TXT".inp","r")){op(TXT".inp","r",stdin);op(TXT".out","w",stdout);}

using namespace std;
int n,m,d[1005][1005];
bool x[1005][1005],vs[1005][1005];
std::vector<pair<int,int>> a[1005][1005];
queue<pair<int,int>> tr;
void cv(int &dem,int i,int j)
{
    dem+=!x[i][j+1];
    dem+=!x[i][j-1];
    dem+=!x[i+1][j];
    dem+=!x[i-1][j];
}
void bfs(pair<int,int> i,int &dientich,int &chuvi)
{
    queue<pair<int,int>> q;
    pair<int,int> c;
    q.push(i);
    vs[i.fi][i.se]=1;
    dientich++;
    cv(chuvi,i.fi,i.se);
    while(!q.empty())
    {
        c=q.front();
        q.pop();
        for(pair<int,int> &j:a[c.fi][c.se])
        {
            if(!vs[j.fi][j.se])
            {
                cv(chuvi,j.fi,j.se);
                dientich++;
                d[j.fi][j.se]=d[c.fi][c.se]+1;
                vs[j.fi][j.se]=1;
                q.push(j);
            }
        }
    }
}
main()
{
    ios;
    freo;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>x[i][j];
            if(x[i][j])
                tr.push({i,j});
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(x[i][j]&&x[i][j+1])
            {
                a[i][j].push_back({i,j+1});
                a[i][j+1].push_back({i,j});
            }
            if(x[i][j]&&x[i+1][j])
            {
                a[i][j].push_back({i+1,j});
                a[i+1][j].push_back({i,j});
            }
            if(x[i][j]&&x[i][j-1])
            {
                a[i][j].push_back({i,j-1});
                a[i][j-1].push_back({i,j});
            }
            if(x[i][j]&&x[i-1][j])
            {
                a[i][j].push_back({i-1,j});
                a[i-1][j].push_back({i,j});
            }
        }
    }
    pair<int,int> c;
    int dientich=0,chuvi=0,MAXdt=0,MAXchuvi=0;
    while(!tr.empty())
    {
        dientich=0;
        chuvi=0;
        c=tr.front();
        tr.pop();
        if(!vs[c.fi][c.se])
        {
            bfs(c,dientich,chuvi);
            MAXdt=max(MAXdt,dientich);
            MAXchuvi=max(MAXchuvi,chuvi);
        }
    }
    cout<<MAXdt<<"\n"<<MAXchuvi;
}
