#include <bits/stdc++.h>
using namespace std;
struct node
{
int x, y;
};
int n, m;
int a[55][55];
bool vis[55][55];
string two[16] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
"1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int bfs(int x, int y)
{
queue<node> q;
q.push((node){x, y});
vis[x][y] = true;
int sum = 0;
while (!q.empty())
{
node u = q.front();
q.pop();
sum++;
if (two[a[u.x][u.y]][0] == '0' && !vis[u.x + 1][u.y])
q.push((node){u.x + 1, u.y}), vis[u.x + 1][u.y] = true;
if (two[a[u.x][u.y]][1] == '0' && !vis[u.x][u.y + 1])
q.push((node){u.x, u.y + 1}), vis[u.x][u.y + 1] = true;
if (two[a[u.x][u.y]][2] == '0' && !vis[u.x - 1][u.y])
q.push((node){u.x - 1, u.y}), vis[u.x - 1][u.y] = true;
if (two[a[u.x][u.y]][3] == '0' && !vis[u.x][u.y - 1])
q.push((node){u.x, u.y - 1}), vis[u.x][u.y - 1] = true;
}
return sum;
}
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> a[i][j];
int ans1 = 0, ans2 = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (!vis[i][j])
{
ans2 = max(ans2, bfs(i, j));
ans1++;
}
cout << ans1 << "\n"
<< ans2;
return 0;
}