#include<iostream>
#include<cstring>
using namespace std;
void dfs(char a[100][100], char ch, int x, int y);
int find(char a[100][100], char ch);
int sum; //总数
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int sx, sy;//初始位置
char farm[100][100]; //范围
int  judge[100][100];
int n, m;   //n*m
int main()
{
	while (1)
	{
		cin >> n >> m;
		if (n == 0 && m == 0)
			break;
		char a = '@';
		char b = '#';
		char c = '*';
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				cin >> farm[i][j];
		memset(judge, 0,sizeof(judge));
		sum = 0;
		sx = 0;
		sy = 0;
		while (find(farm,a)!=0)
		{
			/*cout << "**********************************************" << endl;
			cout << endl;
			cout << endl;*/
			sum++;
			dfs(farm, a, sx,sy);
			/*for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < m; j++)
					cout << farm[i][j];
				cout << endl;
			}
			cout << sum << endl;*/

			
		}
		while (find(farm, b) != 0)
		{
			sum++;
			dfs(farm, b,sx,sy);
		}
		while (find(farm, c) != 0)
		{
			sum++;
			dfs(farm, c,sx, sy);
		}
		cout << sum << endl;
	}
	return 0;
}
void dfs(char a[100][100], char ch, int x, int y)
{
	int nx = x;
	int ny = y;
	judge[nx][ny]=1;//此时的点已经是符合条件的点
	for (int t = 0; t < 4; t++)
	{
		if (a[nx + dx[t]][ny + dy[t]] == ch && nx + dx[t] >= 0 && nx + dx[t] < n&&ny + dy[t] >= 0 && ny + dy[t] < m&&judge[nx + dx[t]][ny + dy[t]] ==0)
		{
			//nx+=dx[t]
			//ny += dy[t];//此处值改变了 无法回溯，
			dfs(a, ch, nx + dx[t], ny + dy[t]);
		}
	}
}

int find(char a[100][100],char ch)   //找符号
{
	int flag = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (a[i][j] == ch&&judge[i][j]==0)     //得到 准确位置
			{
				flag = 1;
				sx = i;
				sy = j;
				break;
			}
		}
		if (flag == 1)
			break;
	}
	if (flag == 1)
		return 1;  //定位，改变x,y
	else
		return 0;  //余下矩阵没有特定符号
}
