#include<stdio.h>
#include<math.h>

int Walk(int, int, int, int, int);

int map[20][20];

int main()
{
	char input[21];
	int i, j, ans, w, h, sH, sW;
	
	while(1)
	{
		sH = sW = 0;
		
		scanf("%d %d", &w, &h);
		
		if(w == 0 && h == 0) break;
		
		for(i = 0; i < h; i++)
		{
			scanf(" %s", input);
			
			for(j = 0; j < w; j++)
			{
				if(input[j] == '.')
				{
					map[i][j] = 1;
				} else if(input[j] == '#') {
					map[i][j] = 0;
				} else {
					map[i][j] = 1;
					sH = i;
					sW = j;
				}
			}
		}
		
		ans = Walk(0, sH, sW, h, w);
		
		printf("%d\n", ans);
	}
	
	return 0;
}

int Walk(int count, int h, int w, int maxH, int maxW)
{
	int i, j, ans, dh, dw, ch, cw;
	
	map[h][w] |= 2;
	ans = count + 1;
	
	for(i = 0; i < 4; i++)
	{
		dw = cos(90 * i * M_PI / 180);
		dh = sin(90 * i * M_PI / 180);
		
		ch = h + dh;
		cw = w + dw;
		
		if(ch > -1 && ch < maxH && cw > -1 && cw < maxW && (map[ch][cw] & 3) == 1)
		{
			ans = Walk(ans ,ch, cw, maxH, maxW);
		}
	}
	
	return ans;
}