#include<iostream>
using namespace std;

char F[102][102];

void DFSapple(int X,int Y)
{
	if(F[X][Y]!='@')
		return;

	F[X][Y] = '.';
	
	DFSapple(X-1,Y  );
	DFSapple(X  ,Y+1);
	DFSapple(X+1,Y  );
	DFSapple(X  ,Y-1);
}	

void DFSpersimmon(int X,int Y)
{
	if(F[X][Y]!='#')
		return;

	F[X][Y] = '.';
	
	DFSpersimmon(X-1,Y  );
	DFSpersimmon(X  ,Y+1);
	DFSpersimmon(X+1,Y  );
	DFSpersimmon(X  ,Y-1);
}	

void DFSorange(int X,int Y)
{
	if(F[X][Y]!='*')
		return;

	F[X][Y] = '.';
	
	DFSorange(X-1,Y  );
	DFSorange(X  ,Y+1);
	DFSorange(X+1,Y  );
	DFSorange(X  ,Y-1);
}	

int main()
{
	while(true){
		int N,M;
		cin >> M >> N;
		if(N==0&&M==0)
			break;

		for(int x=1;x<=N;x++)
			for(int y=1;y<=M;y++)
				cin >> F[x][y];

		int cnt = 0;
		for(int x=1;x<=N;x++)
			for(int y=1;y<=M;y++)
				if(F[x][y]=='@'){
					cnt++;
					DFSapple(x,y);
				}

		for(int x=1;x<=N;x++)
			for(int y=1;y<=M;y++)
				if(F[x][y]=='#'){
					cnt++;
					DFSpersimmon(x,y);
				}

		for(int x=1;x<=N;x++)
			for(int y=1;y<=M;y++)
				if(F[x][y]=='*'){
					cnt++;
					DFSorange(x,y);
				}

		cout << cnt << endl;
	}

	return 0;
}
