#include <stdio.h>
//#include <conio.h>

#define UP [y-1][x]
#define DOWN [y+1][x]
#define LEFT [y][x-1]
#define RIGHT [y][x+1]
#define CURR [y][x]

int max = 0;
int count_for_sell = 0;
int count = 0;
int first_x = -1;
int first_y = -1;


void check_func(int y, int x, int mY, int mX, int **arr_check)
{
	if(first_x == -1)
		first_x = x;
	if(first_y == -1)
		first_y = y;
	
	arr_check CURR = 3;
	if(x < mX-1)
	{
		if(arr_check RIGHT == 1)
		{
			count_for_sell++;
			check_func(y, x+1, mY, mX, arr_check);
		}
	}
	if(y < mY-1)
	{
		if(arr_check DOWN == 1)
		{
			count_for_sell++;
			check_func(y+1, x, mY, mX, arr_check);
		}
	}
	if(x > 0)
	{
		if(arr_check LEFT == 1)
		{
			count_for_sell++;
			check_func(y, x-1, mY, mX, arr_check);
		}
	}
	if(y > 0)
	{
		if(arr_check UP == 1)
		{
			count_for_sell++;
			check_func(y-1, x, mY, mX, arr_check);
		}
	}
	if(first_x == x && first_y == y)
	{
		count++;
		if(count_for_sell > max)
			max = count_for_sell;
		count_for_sell = 0;
		first_x = -1;
		first_y = -1;
	}
}

int main()
{
	int x,y;
	scanf("%d", &y);
	scanf("%d", &x);

	int **arr;
	arr = new int*[y];
	

	for(int i = 0; i < y; i++)
	{
		arr[i] = new int[x];
		for(int j = 0; j < x; j++)
		{
			scanf("%d", &arr[i][j]);
		}
	}
	for(int i = 0; i < y; i++)
	{
		for(int j = 0; j < x; j++)
		{
			if(arr [i][j] == 1)
			{
				count_for_sell++;
				check_func(i,j,y,x,arr);
			}
		}
	}
	printf("%d %d", count, max);
	//getch();
	return 0;

}