#include<bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, m, ans = 0;
char a[N][N];
bool use[N][N];
void dfs(int x, int y, int z) {
if (a[x][y] == '#' || use[x][y] || x < 1 || y < 1 || x > m || y > n) {
if (z > ans)
ans = z;
return;
}
use[x][y] = true;
dfs(x + 1, y, z + 1);
dfs(x - 1, y, z + 1);
dfs(x, y + 1, z + 1);
dfs(x, y - 1, z + 1);
}
int main() {
scanf("%d%d", &n, &m);
int x, y;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
if (a[i][j] == '@')
x = j, y = i;
}
dfs(x, y, 0);
printf("%d", ans);
return 0;
}