#include #include #include #include #include #include #include #include using namespace std; int w, h; int sx, sy; int table[20][20]; int reach[20][20]; set > up; void Run(int x, int y) { if(x < 0 || y < 0 || x >= w || y >= h) return; if(!table[x][y] || reach[x][y]) return; reach[x][y] = 1; up.insert(make_pair(x,y)); } int main() { while(cin >> w >> h) { if(w == 0) break; for(int i = 0; i < h; ++i) { string line; cin >> line; for(int j = 0; j < w; ++j) { if(line[j] == '#') { table[j][i] = 0; } else { table[j][i] = 1; if(line[j] == '@') { sx = j; sy = i; } } } } memset(reach, 0, sizeof(reach)); reach[sx][sy] = 1; up.clear(); up.insert(make_pair(sx, sy)); while(!up.empty()) { int x = up.begin()->first; int y = up.begin()->second; up.erase(up.begin()); Run(x+1,y); Run(x-1,y); Run(x,y+1); Run(x,y-1); } int r = 0; for(int i = 0; i < w; ++i) for(int j = 0; j < h; ++j) if(reach[i][j]) ++r; cout << r << endl; } }