#include <fstream>
#include <vector>
#include <stdint.h>

using namespace std;

int maxP = INT32_MIN;
int maxS = INT32_MIN;
vector <vector <int> > temp;

void FindMax(int &m, int &n, int &totalS, int &totalP, int p, int q)
{
	if (p >= 0 && p < m && q >= 0 && q < n)
	{
		if (temp[p][q] == 1)
		{
			if (p > 0)
			{
				if (temp[p - 1][q] == 0)
				{
					totalP++;
				}
			}
			else
			{
				totalP++;
			}
			if (p < m - 1)
			{
				if (temp[p + 1][q] == 0)
				{
					totalP++;
				}
			}
			else
			{
				totalP++;
			}
			if (q > 0)
			{
				if (temp[p][q - 1] == 0)
				{
					totalP++;
				}
			}
			else
			{
				totalP++;
			}
			if (q < n - 1)
			{
				if (temp[p][q + 1] == 0)
				{
					totalP++;
				}
			}
			else
			{
				totalP++;
			}
			temp[p][q] = 2;
			totalS++;
			FindMax(m, n, totalS, totalP, p + 1, q);
			FindMax(m, n, totalS, totalP, p - 1, q);
			FindMax(m, n, totalS, totalP, p, q + 1);
			FindMax(m, n, totalS, totalP, p, q - 1);
		}
	}
}

int main()
{
	ifstream input("bonhoa.inp");
	ofstream output("bonhoa.out");
	int m, n;
	int totalS = 0;
	int totalP = 0;
	input >> m >> n;
	vector <vector <int> > a (m, vector <int>(n));
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			input >> a[i][j];
		}
	}
	temp = a;
	for (int p = 0; p < m; p++)
	{
		for (int q = 0; q < n; q++)
		{
			FindMax(m, n, totalS, totalP, p, q);
			if (totalS > maxS)
			{
				maxS = totalS;
			}
			if (totalP > maxP)
			{
				maxP = totalP;
			}
			totalS = 0;
			totalP = 0;
		}
	}
	output << maxS << '\n' << maxP;
	input.close();
	output.close();
	return 0;
}