#include<stdio.h>

unsigned short room[22][22];

void DFS(unsigned short x, unsigned short y);

int main(void) {

	unsigned short W, H, manx, many;
	unsigned short i, j, count = 0;
	char c[32];
	while(1){
		count=0;
		scanf("%hu%hu%*c", &W, &H);
		if(W==0 && H==0) break;
		for(i = 0; i < H + 2; i++) {
			if(i>0 && i<H+1) scanf("%s",c);
			for(j = 0; j < W + 2; j++) {
				if(i == 0 || j == 0 || i == H + 1 || j == W + 1) room[i][j] = 0;
				else{
					//putchar(c[j-1]);
					if(c[j-1]=='#') room[i][j]=0;
					else if(c[j-1]=='.') room[i][j]=1;
					else room[i][j]=2;
				}

				if(room[i][j] == 2) {
					manx = i;
					many = j;
					room[i][j] = 1;
				}
			}
		}
		DFS(manx, many);

		for(i = 1; i < H + 1; i++) for(j = 1; j < W + 1; j++) count += (room[i][j] == 2);

		printf("%hd\n", count);
	}
	return 0;
}

void DFS(unsigned short x, unsigned short y) {
	if(room[x][y] != 1) return;
	room[x][y] = 2;
	DFS(x - 1, y);
	DFS(x + 1, y);
	DFS(x, y - 1);
	DFS(x, y + 1);
}