#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <memory.h>
using namespace std;
#define MAX_SIZE 502
int board[MAX_SIZE][MAX_SIZE];
bool visited[MAX_SIZE][MAX_SIZE];
int n = 0, m = 0;
int dx[4]{ 1, 0, -1, 0 };
int dy[4]{ 0, 1, 0, -1 };
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
cin >> board[i][j];
}
int mx = 0; // 그림의 최대값
int num = 0; // 그림의 수
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (board[i][j] == 0 ||
visited[i][j])
continue;
num++;
queue<pair<int, int>> q;
visited[i][j] = true;
q.push({ i,j });
int area = 0;
while (!q.empty())
{
area++;
pair<int, int> cur = q.front();
q.pop();
for (int dir = 0; dir < 4; dir++)
{
int nx = cur.first + dx[dir];
int ny = cur.second + dy[dir];
if (nx < 0 ||
nx >= n ||
ny < 0 ||
ny >= m)
continue;
if (visited[nx][ny] ||
!board[nx][ny])
continue;
visited[nx][ny] = true;
q.push({ nx,ny });
}
}
mx = max(mx, area);
}
}
cout << num << '\n' << mx;
return 0;
}