#include <stdio.h>

int main(void){
    int x,y;
    int now_x,now_y;
    int tmp;
    int board[22][22];

    while(1){
        scanf("%d %d", &x, &y);
        
        if(x == 0 && y == 0){
            return 0;
        }

        for(int i = 0; i < 22; i++){
            for(int j = 0; j < 22; j++){
                board[i][j] = -1;
            }
        }

        for(int i = 1; i <= y; i++){
            for(int j = 1; j <= x; j++){
                tmp = getchar();
                if(tmp == '\n'){
                    tmp = getchar();
                }
                switch(tmp){
                    case '.': board[i][j] = 1;break;
                    case '#': board[i][j] = 0;break;
                    case '@': board[i][j] = 2;break;
                }
            }
        }

        int end_flag = 0;
        while(end_flag == 0){
            end_flag = 1;

            for(int i = 1; i <= y; i++){
                for(int j = 1; j <= x; j++){
                    if(board[i][j] == 2){
                        if(board[i + 1][j] == 1){
                            end_flag = 0;
                            board[i + 1][j] = 2;
                        }
                        if(board[i - 1][j] == 1){
                            end_flag = 0;
                            board[i - 1][j] = 2;
                        }
                        if(board[i][j + 1] == 1){
                            end_flag = 0;
                            board[i][j + 1] = 2;
                        }
                        if(board[i][j - 1] == 1){
                            end_flag = 0;
                            board[i][j - 1] = 2;
                        }
                    }
                }
            }
        }
        
        int cnt = 0;
        for(int i = 1; i <= y; i++){
           for(int j = 1; j <= x; j++){
           //    printf("%2d", board[i][j]);
               if(board[i][j] == 2){
                   cnt++;
               }
           }
           //printf("\n");
        }

        printf("%d\n", cnt);

    }

}