#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std;
int dx[4] = { 0,0,-1,1 };
int dy[4] = { -1,1,0,0 };
struct Pos
{
Pos() = default;
Pos(int a, int b) : x(a), y(b)
{
}
int x;
int y;
bool operator!= (const Pos& other)const
{
if (x == other.x)
{
if (y == other.y)
{
return false;
}
}
return true;
}
bool operator== (const Pos& other)const
{
return !(*this != other);
}
bool operator<(const Pos& other)const
{
if (x != other.x)
{
return x < other.x;
}
return y < other.y;
}
};
int main(void)
{
int n, m;
cin >> n >> m;
vector<vector<int>> vec(n, vector<int>(m, -1));
for (int i = 0; i < vec.size(); ++i)
{
for (int j = 0; j < vec[i].size(); ++j)
{
cin >> vec[i][j];
}
}
int answer = 0;
vector<vector<bool>> visited(n, vector<bool>(m, false));
queue<Pos> q;
map<Pos, int> Map;
int mNum = 0;
for (int i = 0; i < vec.size(); ++i)
{
for (int j = 0; j < vec[i].size(); ++j)
{
if (vec[i][j] == 1 && visited[i][j] == false)
{
q.push(Pos(i, j));
visited[i][j] = true;
Pos mNum(i,j);
int fakeAnswer = 1;
Map[mNum] = 1;
while (!q.empty())
{
Pos recv = q.front();
q.pop();
for (int i = 0; i < 4; ++i)
{
int x = recv.x + dx[i];
int y = recv.y + dy[i];
Pos next(x, y);
if (x < 0 || x >= n || y < 0 || y >= m)
{
continue;
}
if (visited[x][y] == true)
{
continue;
}
if (vec[x][y] == 0)
{
continue;
}
q.push(next);
visited[x][y] = true;
fakeAnswer++;
Map[mNum]++;
}
}
if (answer < fakeAnswer)
{
answer = fakeAnswer;
}
}
}
}
cout << Map.size() << "\n" << answer;
return 0;
}