#include #include using namespace std; int a[101][101]; char x; int n,m,px,py; queue > coada; int main() { int i,j; cin>>n>>m; for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ cin>>x; if(x=='.') a[i][j]=1; else if (x=='&') a[i][j]=-1; } } /* for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ if(a[i][j]==0) dfs(i,j); } } cica pleaca doar din 1 1*/ coada.push(make_pair(1,1)); a[1][1]=1; int sumcur=0; int summax=0; while(!coada.empty()){ px=coada.front().first; py=coada.front().second; if(a[px][py+1]==1){ coada.push(make_pair(px,py+1)); a[px][py+1]=a[px][py]+1; sumcur=a[px][py]+1; } if(sumcur>summax) summax=sumcur; if(a[px+1][py]==1){ coada.push(make_pair(px+1,py)); a[px+1][py]=a[px][py]+1; sumcur=a[px][py]+1; } if(sumcur>summax) summax=sumcur; coada.pop(); } cout<