https://www.acwing.com/problem/content/1115/
#include<bits/stdc++.h>
using namespace std;
int dx[]={-1,1,0,0},dy[]={0,0,-1,1};
int flag[25][25]={0};
int n,m;
char china[25][25];
int dfs(int x,int y)
{
flag[x][y]=1;
int count=1;
for(int i=0;i<4;i++)
{
int a=x+dx[i],b=y+dy[i];
if(a<0||b<0||a>=n||b>=m)continue;
if(china[a][b]=='#')continue;
if(flag[a][b])continue;
count+=dfs(a,b);
}
return count;
}
int main(){
while(1){
cin>>m>>n;
if(m==0||n==0)break;
memset(flag,0,sizeof flag);
int x,y;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
cin>>china[i][j];
if(china[i][j]=='@')x=i,y=j;
}
cout<<dfs(x,y)<<endl;
}
return 0;
}