#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

const int MAX = 1000005;
typedef pair <int, int> PT;
int M, N;
char s[MAX];
int comp = 0;
int mx = -1;
int cur;
int up;

inline void bfs(int v)
{
	queue <int> q;
	q.push(v);
	s[v] = '0';

	while (!q.empty())
	{
		v = q.front();
		q.pop();
	
		++cur;

		if (v % N != N - 1 && s[v + 1] == '1')
		{
			q.push(v + 1);
			s[v + 1] = '0';
		}

		if (v % N != 0 && s[v - 1] == '1')
		{
			q.push(v - 1);
			s[v - 1] = '0';
		}

		if (v - N >= 0 && s[v - N] == '1')
		{
			q.push(v - N);
			s[v - N] = '0';
		}

		if (v + N < up && s[v + N] == '1')
		{
			q.push(v + N);
			s[v + N] = '0';
		}
	}
}

int main()
{
	scanf("%d %d\n", &M, &N);
	up = N * M;

	for (int i = 0; i < M; i++)
	{
		gets(s + i * N);
	}

	for (int i = 0; i < up; i++)
	{
		if (s[i] == '1')
		{
			++comp;
			cur = 0;
			bfs(i);

			if (cur > mx)
			{
				mx = cur;
			}
		}
	}

	printf("%d %d\n", comp, mx);

	return 0;
}
