#include <stdio.h>
#include <fstream>
#include <string>
using namespace std;

void remove(int x, int y);
//	string floor[44];
	char floor[44][44];
	char temp;
	int a,b,c,d,x,y,total,hei,wid;
int main()
{
//	FILE * pfile;
//	pfile= fopen("DATA3.txt", "w+");
	ifstream infile;
	ofstream outfile;
	infile.open("DATA3.txt", ios::in);
	outfile.open("OUT3.txt", ios::out);
//	fscanf(pfile, "%d", &hei);
//	fscanf(pfile, "%d", &wid);
	infile >> hei;
	infile >> wid;
/*	for (a=0; a<=42; a++)
	{
		floor[b]= 35;
	}
*/	for (a=1; a<=hei; a++)
	{
		for (b=1; b<=wid; b++)
		{
			infile >> floor[a][b];
		}
	}
/*	for (a=1; a<=hei; a++)
	{
		for (b=1; b<=wid; b++)
		{
			outfile << floor[a][b];
		}
		outfile << "\n";
	}
*/	
	for (c=1; c<=5; c++)
	{
		for (a=1; a<=hei; a++)
		{
			for (b=1; b<=wid; b++)
			{

				if (int(floor[a][b])==48+c)
				{
					total=0;
					remove(a,b);
					total++;
					outfile << total <<"\n";
				}
			}
		}
	}
	return 0;
}
void remove(int x, int y)
{	
	if (int(floor[x+1][y])==46)
	{
		total++;
		floor[x+1][y]=35;
		remove(x+1,y);
	}
	if (int(floor[x][y+1])==46)
	{
		total++;
		floor[x][y+1]=35;
		remove(x,y+1);
	}
	if (int(floor[x-1][y])==46)
	{		
		total++;
		floor[x-1][y]=35;
		remove(x-1,y);
	}
	if (int(floor[x][y-1])==46)
	{		
		total++;
		floor[x][y-1]=35;
		remove(x,y-1);
	}
}

