#include <fstream>

int mxp = -2e9,  mxs = -2e9,p,s,q[4] = {0,1,-1,0},e[4] = {1,0,0,-1};
long long a[1000][1000];

using namespace std;

int loang(int l, int r)
{
    a[l][r] = -1; s++;
    for (int o = 0; o < 4; o++)
        if (a[l+q[o]][r+e[o]] == 0) p++;
    for (int o = 0; o < 4; o++)
        if (a[l+q[o]][r+e[o]] == 1) loang(l+q[o],r+e[o]);
}

int main()
{
    ios::sync_with_stdio(false);
    ifstream fi("bonhoa.inp");
    ofstream fo("bonhoa.out");
    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++) a[i][0] = 0;
    for (int i = 1; i <= n; i++) a[0][i] = 0;
    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);
            if (mxp < p && mxs < s)
            {
                mxp = p; mxs = s;
            }
        }
    fo << "Dien tich lon nhat: " << mxs << endl << "Chu vi lon nhat: " << mxp << endl;
    return 0;
}
