#include <stdio.h>
#include <iostream>

using namespace std;

int number=0;
int square=0;
int currentSquare = 0;


void getPyatno(int M, int N, int x, int y)
{
	if (x < M - 1)
	{
		if (a[x+1][y]==1 && isUsed[x+1][y]==false)
		{		
			isUsed[x+1][y] = true;
			currentSquare ++;
			getPyatno( M, N, x+1, y);
		}

		if (y < N-1){
			if (a[x+1][y+1]==1 && isUsed[x+1][y+1]==false)
			{
				isUsed[x+1][y+1] = true;
				currentSquare++;
				getPyatno( M, N, x+1, y+1);
			}}

		if (y>0){
			if (a[x+1][y-1]==1 && isUsed[x+1][y-1]==false)
			{
				isUsed[x+1][y-1] = true;
				currentSquare++;
				getPyatno( M, N, x+1, y-1);
			}}
	}

	if (x>0){
		if (a[x-1][y]==1 && isUsed[x-1][y]==false)
		{
			isUsed[x-1][y] = true;
			currentSquare++;
			getPyatno( M, N, x-1, y);
		}

		if (y < N -1){
			if (a[x-1][y+1]==1 && isUsed[x-1][y+1]==false)
			{
				isUsed[x-1][y+1] = true;
				currentSquare++;
				getPyatno( M, N, x-1, y+1);
			}
		}
		if (y > 0){
			if (a[x-1][y-1]==1 && isUsed[x-1][y-1]==false)
			{
				isUsed[x-1][y-1] = true;
				currentSquare++;
				getPyatno( M, N, x-1, y-1);
			}}
	}

	if (y < N - 1)
		if (a[x][y+1]==1 && isUsed[x][y+1]==false)
		{
			isUsed[x][y+1] = true;
			currentSquare++;
			getPyatno( M, N, x, y+1);
		}
	if (y > 0)
		if (a[x][y-1]==1 && isUsed[x][y-1]==false)
		{
			isUsed[x][y-1] = true;
			currentSquare++;
			getPyatno( M, N, x, y-1);
		}

		if (currentSquare > square){
			square = currentSquare;
		}
	currentSquare = 0;
}


int main ()
{
	int *(&a) = new int[6][7];
	bool  isUsed[6][7];

	int M, N ;
	freopen("STDIN", "r", stdin);
	cin >> M >> N;

	for (int i = 0; i<M ; i++)
	{
		for (int j = 0; j < N; j++)
		{
			cin >> a[i][j];
			isUsed[i][j] = false;
		} 
	}

	fclose(stdin);
	

	for (int i = 0; i < M; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (a[i][j] == 1 && isUsed[i][j] == false)
			{
				number++;
				currentSquare = 1;
				isUsed[i][j] = true;
				getPyatno( M, N, i, j);
			}
		}
	}
	

	freopen("STDOUT", "a+" , stdout);
	cout << number << " " << square;
	fclose(stdout);

	return 0;
}