#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;



int main()
{
	//int i1[100000]={0},j1[100000]={0};
	vector<int>i1(100010,0);
	vector<int>j1(100010,0);
	//freopen("stdin","r",stdin);
	int n,m;
	cin>>m>>n;
	int s=1;
	for (int i=1;i<=m;i++)
		for (int j=1;j<=n;j++)
		{
			char temp;
			cin>>temp;
			if (temp=='1')
			{
				i1[s]=i;
				j1[s]=j;
				s++;
			}
		}
	int q[100010],w=2;
	q[1]=1;
	bool f[100010]={false};
	f[1]=true;
	for (int i=1;i<s;i++)
	{
		for (int j=1;j<s;j++)
		{
			if ((i1[i]==i1[j])&&(abs(j1[i]-j1[j])==1))
			{
				q[j]=q[i];
				f[j]=true;
			}
			
			else if ((abs(i1[i]-i1[j])==1)&&(j1[i]==j1[j]))
			{
				q[j]=q[i];
				f[j]=true;
			}
			else if ((f[j]==false)&&(i!=j))
			{
				q[j]=w;
				w++;
			}
		}

	}
	int max=0;
	int qw[100010]={0};
	map<int,int>po;
	for (int i=1;i<s;i++)
	{
		qw[q[i]]++;
		if (qw[q[i]]>max)
			max=qw[q[i]];
		po[q[i]]=1;
	}
	int th=po.size();
	cout<<th<<" "<<max;

	return 0;
}