DFS
//
// Created by Genes on 2020/10/12.
//
// 红与黑
// 需要注意, n是列, m是行
#include<iostream>
#include<cstring>
using namespace std;
const int N = 2e1 + 5;
int n, m;
char g[N][N];
bool st[N][N];
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
int ans = 1;
int dfs(int x, int y) {
int cnt = 1;
st[x][y] = true;
for (int i = 0; i < 4; i++) {
int a = x + dx[i], b = y + dy[i];
if (a < 0 || a >= n || b < 0 || b >= m) {
continue;
}
if (g[a][b] != '.') {
continue;
}
if (st[a][b]) {
continue;
}
cnt += dfs(a, b);
// ans++;
}
return cnt;
}
int main() {
while (cin >> m >> n, n || m) { //多组数组 先读入 列, 再读入行
for (int i = 0; i < n; i++) {
scanf("%s", g[i]);
}
int x, y;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (g[i][j] == '@') {
x = i, y = j;
break;
}
}
}
memset(st, false, sizeof st);
printf("%d\n", dfs(x, y));
// dfs(x, y);
// printf("%d\n", ans);
// ans = 1;
}
return 0;
}
BFS
//
// Created by Genes on 2020/10/12.
//
// 红与黑
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
typedef pair<int, int> pii;
const int N = 2e1 + 5;
int n, m;
char g[N][N];
int path[N][N];
int bfs(pii start) {
int cnt = 1;
queue<pii> q;
memset(path, -1, sizeof path);
path[start.first][start.second] = 0;
q.push(start);
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
while (!q.empty()) {
pii t = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int a = t.first + dx[i], b = t.second + dy[i];
if (a < 0 || a >= n || b < 0 || b >= m) {
continue;
}
if (g[a][b] == '#') {
continue;
}
if (path[a][b] != -1) {
continue;
}
path[a][b] = path[t.first][t.second] + 1;
q.push(make_pair(a, b));
cnt++;
}
}
return cnt;
}
int main() {
while (cin >> m >> n, n || m) {
for (int i = 0; i < n; i++) {
scanf("%s", g[i]);
}
pii start;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (g[i][j] == '@') {
start = {i, j};
break;
}
}
}
printf("%d\n", bfs(start));
}
return 0;
}