// MADE BY QT666
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=5000050;
int a[3000][3000],n,m,ans1,ans2,h[3000][3000];
struct data{
int h,len;
}q[N];
int tail;
void pre(){
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
if(a[i][j]) h[i][j]=h[i][j-1]+1;
else h[i][j]=0;
}
}
void work(){
for(int j=1;j<=m;j++){
tail=0;q[++tail]=(data){0,0};
for(int i=1;i<=n;i++){
int gg=i;
while(tail&&h[i][j]<=q[tail].len){
ans1=max(ans1,q[tail].len*(i-q[tail].h));
int g=min(q[tail].len,i-q[tail].h);
ans2=max(ans2,g*g);gg=min(gg,q[tail].h);
tail--;
}
q[++tail]=(data){gg,h[i][j]};
}
}
}
int main(){
freopen("makechess.in","r",stdin);
freopen("makechess.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
scanf("%d",&a[i][j]);
if((i+j)%2) a[i][j]^=1;
}
pre();work();
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++) a[i][j]^=1;
memset(h,0,sizeof(h));pre();work();
printf("%d\n%d",ans2,ans1);
return 0;
}