#include <iostream>
using namespace std;

const int MAXSIZE = 128;
int grid[MAXSIZE][MAXSIZE];
int quad[2*MAXSIZE*MAXSIZE];
int squad[2*MAXSIZE*MAXSIZE];

int power2(int n)
{
	int ans = 1;
	while (ans < n)
		ans *= 2;
	return ans;
}

bool sameChildren(int p)
{
	p *= 4;
	if (quad[p+1] == -1 || quad[p+2] == -1 || quad[p+3] == -1 || quad[p+4] == -1)
		return false;
	int sum = quad[p+1] + quad[p+2] + quad[p+3] + quad[p+4];
	return (sum == 0 || sum == 4);
}

void storeVals(int r, int c, int size, int& loc)
{
	if (size == 1) {
//cout << "storing " << grid[r][c] << "(location " << r << ',' << c << ") in " << loc <<endl;
		squad[loc] = quad[loc] = grid[r][c];
		loc++;
	}
	else {
		storeVals(r, c, size/2, loc);
		storeVals(r, c+size/2, size/2, loc);
		storeVals(r+size/2, c, size/2, loc);
		storeVals(r+size/2, c+size/2, size/2, loc);
	}
}

bool sameTree(int i1, int i2)
{
	if (quad[i1] != quad[i2])
		return false;
	if (quad[i1] != -1)
		return true;
	for(int i=1; i<=4; i++)
		if (!sameTree(4*i1+i, 4*i2+i))
			return false;
	return true;
}

int countSquadNodes(int i)
{
	if (squad[i] == -2)
		return 0;
	if (squad[i] != -1)
		return 1;
	return 1 + countSquadNodes(4*i+1) + countSquadNodes(4*i+2) + countSquadNodes(4*i+3) + countSquadNodes(4*i+4);
}

int main()
{
	int n, m;
	cin >> n >> m;
	while (n != 0) {
		int nn = power2(n);
		int mm = power2(m);
		if (nn < mm)
			nn = mm;
		int startLoc = (nn*nn-1)/3;
//cout << nn << ',' << startLoc << endl;
		for(int i=0; i<startLoc; i++)
			quad[i] = -1;
		int k=0;
		for(int i=0; i<n; i++) {
			for(int j=0; j<m; j++) {
				char ch;
				cin >> ch;
				grid[i][j] = ch-'0';
			}
			for(int j=m; j<nn; j++)
				grid[i][j] = 0;
		}
		for(int i=n; i<nn; i++)
			for(int j=0; j<nn; j++)
				grid[i][j] = 0;
/*for(i=0; i<nn; i++) {
for(int j=0; j<nn; j++)
cout << grid[i][j];
cout << endl;
}
*/
		storeVals(0, 0, nn, startLoc);
/*for(i=0; i<(4*nn*nn-1)/3; i++)
cout << quad[i];
cout << endl;
*/
		int numNodes = (4*nn*nn-1)/3;
		int end = (nn*nn-1)/3;
		do {
			startLoc = (end-1)/4;
			for(int i=startLoc; i<end; i++) {
				if (sameChildren(i)) {
					quad[i] = quad[4*i+1];
					numNodes -= 4;
				}
			}
			end = startLoc;
		} while (end > 0);
		for(int i=0; i<(4*nn*nn-1)/3; i++)
			squad[i] = quad[i];
		for(int i=1; i<(nn*nn-1)/3; i++)
			for(int j=i+1; j<(nn*nn-1)/3; j++)
				if (sameTree(i, j) && quad[i] == -1)
					squad[j] = -2;

		cout << numNodes << ' ' << countSquadNodes(0) << endl;
/*
for(i=0; i<(4*nn*nn-1)/3; i++)
cout << quad[i];
cout << endl;
for(i=0; i<(4*nn*nn-1)/3; i++)
cout << squad[i];
cout << endl;
*/
		cin >> n >> m;
	}
return 0;
}

