#include<bits/stdc++.h>
using namespace std;
const int MAX = 50+5;
typedef pair<int, int> PII;
int n, m, num, mx;
int g[MAX][MAX];
bool v[MAX][MAX];
PII q[MAX*MAX];
int d[4][2] = {0, -1, -1, 0, 0, 1, 1, 0};
int bfs(int r, int c){
int hh = 0, tt = 0, rs = 1;
q[hh] = {r, c};
v[r][c] = true;
while(hh<=tt){
PII t = q[hh++];
r = t.first, c = t.second;
for(int i=0; i<4; i++){
if((g[r][c]>>i)&1) continue;
int rr = r + d[i][0], cc = c + d[i][1];
if(rr<0 || rr>=n || cc<0 || cc>=m || v[rr][cc]) continue;
rs++;
v[rr][cc] = true;
q[++tt] = {rr, cc};
}
}
return rs;
}
int main(){
scanf("%d%d", &n, &m);
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
scanf("%d", &g[i][j]);
}
}
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(!v[i][j]){
mx = max(mx, bfs(i, j));
num++;
}
}
}
cout<< num<< endl<< mx<< endl;
return 0;
}