#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <cmath>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;

#define mp make_pair

void solve() {
	int N, M;
	cin >> N >> M;
	
	vector<string> f(N);
	for (int i = 0; i < N; ++i)
		cin >> f[i];
		
	vector<vi> u(N, vector<int>(M));
	queue<pii> q;
	
	int count = 0;
	int maximal = 0;
	
	for (int r = 0; r < N; ++r) for (int c = 0; c < M; ++c) {
		if (f[r][c] == '1' && u[r][c] == 0) {
			++count;
			q.push(mp(r, c));
			u[r][c] = count;
			int size = 1;
			while (q.empty() == false) {
				int cur_r = q.front().first;
				int cur_c = q.front().second;
				q.pop();
				
				for (int nr = max(0, cur_r - 1); nr <= min(N - 1, cur_r + 1); ++nr)
				for (int nc = max(0, cur_c - 1); nc <= min(M - 1, cur_c + 1); ++nc)
					if (abs(cur_r - nr) + abs(cur_c - nc) == 1)
					if (f[nr][nc] == '1' && u[nr][nc] == 0) {
						++size;
						u[nr][nc] = count;
						q.push(mp(nr, nc));
					}
			}
			if (size > maximal) maximal = size;
		}
	}
	
	cout << count << ' ' << maximal << endl;
}

int main() {
	solve();
	
	return 0;
}
