#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define MAXN 2010
int N,M,a[MAXN][MAXN],l[MAXN][MAXN],r[MAXN][MAXN],h[MAXN][MAXN],ans,x;
int main()
{
scanf("%d%d",&N,&M);
for (int i=1; i<=N; i++)
for (int j=1; j<=M; j++)
scanf("%d",&a[i][j]);
for (int i=1; i<=N; i++)
for (int j=1; j<=M; j++)
if ((i+j)&1) a[i][j]^=1;
for (int i=1; i<=N; i++)
{
for (int j=1,x=0; j<=M; j++)
if (a[i][j]) l[i][j]=x; else l[i][j]=0,x=j;
for (int j=M,x=M+1; j>=1; j--)
if (a[i][j]) r[i][j]=x; else r[i][j]=M+1,x=j;
}
for (int i=1; i<=M+1; i++) r[0][i]=M+1;
for (int i=1; i<=N; i++)
for (int j=1; j<=M; j++)
if (a[i][j])
h[i][j]=h[i-1][j]+1,
l[i][j]=max(l[i][j]+1,l[i-1][j]),
r[i][j]=min(r[i][j]-1,r[i-1][j]);
for (int i=1; i<=N; i++)
for (int j=1; j<=M; j++)
if (a[i][j])
ans=max(ans,(r[i][j]-l[i][j]+1)*h[i][j]),
x=max(x,min((r[i][j]-l[i][j]+1),h[i][j]));
memset(h,0,sizeof(h));
for (int i=1; i<=N; i++)
{
for (int j=1,x=0; j<=M; j++)
if (!a[i][j]) l[i][j]=x; else l[i][j]=0,x=j;
for (int j=M,x=M+1; j>=1; j--)
if (!a[i][j]) r[i][j]=x; else r[i][j]=M+1,x=j;
}
for (int i=1; i<=M+1; i++) r[0][i]=M+1;
for (int i=1; i<=N; i++)
for (int j=1; j<=M; j++)
if (!a[i][j])
h[i][j]=h[i-1][j]+1,
l[i][j]=max(l[i][j]+1,l[i-1][j]),
r[i][j]=min(r[i][j]-1,r[i-1][j]);
for (int i=1; i<=N; i++)
for (int j=1; j<=M; j++)
if (!a[i][j])
ans=max(ans,(r[i][j]-l[i][j]+1)*h[i][j]),
x=max(x,min((r[i][j]-l[i][j]+1),h[i][j]));
printf("%d\n%d\n",x*x,ans);
return 0;
}