#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MAXN 105 int N, M; char A[MAXN][MAXN]; int D[MAXN][MAXN]; bool v[MAXN][MAXN]; queue Q; int di[] = { 0, 1 }; int dj[] = { 1, 0 }; int main() { // freopen("date.in", "r", stdin); // freopen("date.out","w", stdout); scanf("%d %d\n", &N, &M); for(int i = 0; i < N; i++) fgets(A[i], sizeof(A[i]), stdin); if(A[0][0] == '&') { printf("0\n"); return 0; } Q.push(0); Q.push(0); D[0][0] = 1; v[0][0] = true; int ans = 1; while(!Q.empty()) { int pi = Q.front(); Q.pop(); int pj = Q.front(); Q.pop(); ans = max(ans, D[pi][pj]); for(int d = 0; d < 2; d++) { int ni = pi + di[d]; int nj = pj + dj[d]; if(ni < N && nj < M && A[ni][nj] != '&' && D[pi][pj] + 1 > D[ni][nj]) { D[ni][nj] = D[pi][pj] + 1; if(!v[ni][nj]) { v[ni][nj] = true; Q.push(ni); Q.push(nj); } } } v[pi][pj] = false; } printf("%d\n", ans); return 0; }