#include #include #include #include using namespace std; int n,m,d[110][110]; int main() { int maxim = 0; int i = 1, j = 1; scanf("%d%d",&n,&m); for(i = 1; i <= n; i++){ getchar(); for(j = 1; j <= m; j++){ char c = getchar(); if(c == '&') d[i][j] = -1; } } ++m,++n; for(i = 0; i <= m; i++) d[0][i] = -1,d[n][i] = -1; for(j = 0; j <= n; j++) d[j][0] = -1,d[j][m] = -1; pair start; start.first = 1; start.second = 1; queue> Q; pair now; if(d[1][1] == 0) Q.push(start), d[1][1] = 1; while (Q.size()){ now = Q.front(); Q.pop(); i = now.first; j = now.second; if(j < m && i < n){ if(d[i + 1][j] == 0){ d[i + 1][j] = d[i][j] + 1; Q.push(make_pair(i + 1, j)); } if(d[i][j + 1] == 0){ d[i][j + 1] = d[i][j] + 1; Q.push(make_pair(i, j + 1)); } } } for(i = 1; i < n; i++) for(j = 1; j < m; j++){ maxim = max(d[i][j],maxim); } printf("%d\n",maxim); return 0; }