#include <stdio.h>
#include <stdlib.h>

int main(){
	while(1){
		int W, H;
		char s[100];
		char map[50][50];
		int i;
		int count = 0;

		scanf("%d %d\n", &W, &H);
		// printf("%d,%d\n", W, H);
		if((W | H) == 0) break;

		for(i = 0; i < H + 2; i++){
			int j;

			for(j = 0; j < W + 2; j++){
				map[i][j] = -1;
			}
		}

		for(i = 0; i < H; i++){
			int j;

			/* fgets(s, 100, stdin); */
			for(j = 0;j < W; j++){
				int end = 0;
				char c;

				c = getchar();

				switch(c){
				case '.':
					map[i + 1][j + 1] = 0;
					break;
				case '#':
					map[i + 1][j + 1] = -1;
					break;
				case '@':
					map[i + 1][j + 1] = 1;
					break;
				default:
					end = 1;
					break;
				}

				if(end) break;
			}
			getchar();
		}

		while(1){
			int end = 0;

			for(i = 0; i < H + 2; i++){
				int j;

				for(j = 0; j < W + 2; j++){
					if(map[i][j] == 1){
						if(map[i + 1][j] == 0) map[i + 1][j] = end = 1;
						if(map[i - 1][j] == 0) map[i - 1][j] = end = 1;
						if(map[i][j + 1] == 0) map[i][j + 1] = end = 1;
						if(map[i][j - 1] == 0) map[i][j - 1] = end = 1;
					}
				}
			}

			if(end == 0) break;
		}

		for(i = 1; i < H + 1; i++){
			int j;

			for(j = 1; j < W + 1; j++){
				if(map[i][j] == 1) count++;
			}
		}

		printf("%d\n", count);
	}

	exit(EXIT_SUCCESS);
}