//DWITE

#include <iostream>
#include <fstream>
using namespace std;

int mx[4] = {0,0,-1,1};
int my[4] = {-1,1,0,0};

int sx,sy;
int tot;
char field[50][50];

void rec(int y, int x)
{
	field[y][x]='#';
	tot++;
		for (int z=0; z<4; z++)
			if ((y+my[z]>=0) && (y+my[z]<sy) && (x+mx[z]>=0) && (x+mx[z]<sx) && (field[y+my[z]][x+mx[z]]=='.'))
				rec(y+my[z],x+mx[z]);
}

int main()
{
	ifstream f ("DATA3.txt");
	ofstream g ("OUT3.txt");
	int t,a,b;
	int locx[5],locy[5];
			f >> sy;
			f >> sx;
				for (a=0; a<sy; a++)
				{
					for (b=0; b<sx; b++)
					{
						f >> field[a][b];
							if ((field[a][b]>='1') && (field[a][b]<='5'))
							{
								locx[field[a][b]-'1']=b;
								locy[field[a][b]-'1']=a;
							}
					}
				}
				for (a=0; a<5; a++)
				{
					tot=0;
					rec(locy[a],locx[a]);
					g << tot << endl;
				}
	return(0);
}
