#include #include #include #include #include #include #include #include #include using namespace std; void go(vector >& table, int w, int h, int dw, int dh, int W, int H) { w += dw; h += dh; if (w < 0 || W <= w) { return; } if (h < 0 || H <= h) { return; } if (table[h][w] != 0) { return; } table[h][w] = 1; go(table, w, h, -1, 0, W, H); go(table, w, h, 1, 0, W, H); go(table, w, h, 0, -1, W, H); go(table, w, h, 0, 1, W, H); } int main() { int W, H; while (cin >> W >> H, (W || H)) { string str; int w, h; vector > table(H, vector(W)); getline(cin, str); // chop for (int i = 0; i < H; ++i) { getline(cin, str); for (int j = 0; j < W; ++j) { if (str[j] == '.') { table[i][j] = 0; } else if (str[j] == '#') { table[i][j] = -1; } else if (str[j] == '@') { table[i][j] = 1; h = i; w = j; } } } go(table, w, h, -1, 0, W, H); go(table, w, h, 1, 0, W, H); go(table, w, h, 0, -1, W, H); go(table, w, h, 0, 1, W, H); int poly = 0; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (table[i][j] == 1) { ++poly; } } } cout << poly << endl; } }