import java.util.Scanner;
class NodeData{
int x;
int y;
public NodeData(int x,int y){
this.x=x;
this.y=y;
}
}
class Queue{
public NodeData[] myNodeData=new NodeData[400];
public int front=0;
public int rear=0;
public void push(NodeData oNodeData){
myNodeData[rear++]=oNodeData;
}
public NodeData pop(){
return myNodeData[front++];
}
public boolean isEmpty(){
return front==rear;
}
}
public class RedAndBlack {
public static int[] result=new int[1000];
public static int result_count=0;
public static int[][] data;
public static int[] dir_x={-1,0,1,0};
public static int[] dir_y={0,1,0,-1};
public static void bFS(int stax,int stay,int hang,int lie){
NodeData startNodeData=new NodeData(stax,stay);
Queue myQueue=new Queue();
myQueue.push(startNodeData);
data[stax][stay]=2;
while(!myQueue.isEmpty()){
NodeData curNodeData=myQueue.pop();
int cur_x=curNodeData.x;
int cur_y=curNodeData.y;
for(int i=0;i<4;i++){
int next_x=cur_x+dir_x[i];
int next_y=cur_y+dir_y[i];
if(next_x>=0&&next_x<hang&&next_y>=0&&next_y<lie&&data[next_x][next_y]==1){
NodeData nextNodeData=new NodeData(next_x,next_y);
myQueue.push(nextNodeData);
data[next_x][next_y]=2;
}
}
}
}
public static void main(String[] args){
int strat_x=0;
int start_y=0;
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int w=sc.nextInt();
int h=sc.nextInt();
if(w==0&&h==0) break;
int blackNum=0;
char map[][]=new char[h][w];
String[] strArr=new String[h];
for(int i=0;i<h;i++){
strArr[i]=sc.next();
}
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
map[i][j]=strArr[i].charAt(j);
}
}
/*for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
System.out.print(map[i][j]+" ");
}
System.out.println(" ");
}
System.out.println(" ");
System.out.println(" ");
*/
data=new int[h][w];
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(map[i][j]=='.') data[i][j]=1; //black
if(map[i][j]=='#') data[i][j]=0; //red
if(map[i][j]=='@') {
data[i][j]=1; //red
strat_x=i;
start_y=j;
}
}
}
/*for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
System.out.print(data[i][j]+" ");
}
System.out.println(" ");
}
System.out.println(" ");
System.out.println(" ");*/
bFS(strat_x,start_y,h,w);
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(data[i][j]==2) blackNum++;
}
}
/*for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
System.out.print(data[i][j]+" ");
}
System.out.println(" ");
}*/
result[result_count++]=blackNum;
//System.out.println(blackNum);
}
for(int i=0;i<result_count;i++){
System.out.println(result[i]);
}
}
}