#include #include using namespace std; queue > c; char a[105][105]; int d[105][105],i,j,n,m,x,y,z,t,mx; int main() { cin >> n >> m; for (i=1;i<=n;i++) for (j=1;j<=m;j++) cin >> a[i][j]; if (a[1][1]=='&') { cout << 0; return 0; } d[1][1]=1; mx=1; c.push(make_pair(1,1)); while (!c.empty()) { x=c.front().first; y=c.front().second; c.pop(); if (x!=n) { z=x+1; t=y; if ((d[z][t]==0) && (a[z][t]=='.')) { d[z][t]=d[x][y]+1; if (d[z][t]>mx) mx=d[z][t]; c.push(make_pair(z,t)); } } if (y!=m) { z=x; t=y+1; if ((d[z][t]==0) && (a[z][t]=='.')) { d[z][t]=d[x][y]+1; if (d[z][t]>mx) mx=d[z][t]; c.push(make_pair(z,t)); } } } cout << mx; return 0; }