1 /*比较简单的广搜题目*/
2 #include<iostream>
3 using namespace std;
4 #include<cstdio>
5 #include<cstring>
6 #include<queue>
7 int w,h;
8 int jz[25][25]={0};
9 struct poi{
10 int x,y;
11 };
12 int xq,yq;
13 int xx[]={1,-1,0,0};
14 int yy[]={0,0,1,-1};
15 void input()
16 {
17 char s[25];
18 for(int i=1;i<=h;++i)
19 {
20 scanf("%s",s+1);
21 for(int j=1;j<=w;++j)
22 {
23 if(s[j]==‘#‘)
24 jz[i][j]=1;
25 if(s[j]==‘@‘)
26 {
27 xq=i;yq=j;
28 }
29 }
30 }
31 }
32 int bfs()
33 {
34 int ans=0;
35 poi p;
36 p.x=xq;p.y=yq;
37 queue<poi>que;
38 que.push(p);
39 while(!que.empty())
40 {
41 poi k=que.front();
42 que.pop();
43 int x=k.x,y=k.y;
44 jz[x][y]=2;
45 for(int i=0;i<4;++i)
46 {
47 int x1=x+xx[i],y1=y+yy[i];
48 if(x1>=1&x1<=h&y1>=1&&y1<=w&&jz[x1][y1]==0)
49 {
50 que.push(poi{x1,y1});
51 }
52 }
53 }
54 for(int i=1;i<=h;++i)
55 for(int j=1;j<=w;++j)
56 if(jz[i][j]==2) ans++;
57 return ans;
58 }
59 int main()
60 {
61 while(scanf("%d%d",&w,&h)==2)
62 {
63 if(w==0&&h==0) break;
64 memset(jz,0,sizeof(jz));
65 input();
66 printf("%d\n",bfs());
67 }
68 return 0;
69 }