#include #include #include #include using namespace std; char a[105][105]; int n,m; queue > Q; int DM[105][105]; int main() { //freopen("data.in", "r", stdin); //freopen("data.out", "w", stdout); scanf("%d %d\n", &n, &m); for ( int i = 1; i <= n; i++ ) { scanf("%s\n", &a[i][0]+1); } if (a[1][1] == '&') { printf("0\n"); return 0; } Q.push(make_pair(1,1)); DM[1][1] = 1; while (!Q.empty()) { pair top = Q.front(); Q.pop(); if (a[top.first][top.second + 1] == '.') { if (DM[top.first][top.second + 1] < DM[top.first][top.second] + 1) { Q.push(make_pair(top.first, top.second + 1)); DM[top.first][top.second + 1] = DM[top.first][top.second] + 1; } } if (a[top.first + 1][top.second] == '.') { if (DM[top.first + 1][top.second] < DM[top.first][top.second] + 1) { Q.push(make_pair(top.first + 1, top.second)); DM[top.first + 1][top.second] = DM[top.first][top.second] + 1; } } } int max = -1; for ( int i = 1; i <= n; i++ ) { for ( int j = 1; j <= m; j++ ) { if ( DM[i][j] > max) max = DM[i][j]; } } printf("%d\n", max); return 0; }