#include #include using namespace std; int di[]={1,0}; //initializare pentru avansare int dj[]={0,1}; int ok(int i,int j,int n,int m) { if(i>0&&i<=n&&j>0&&j<=m) return 1; //verificam daca am iesit din matrice return 0; } int main() { long n,m,i,j,a[101][101],q[1000][2],nq,pq,k,ni,nj; char c[101][101]; memset (a,-1,sizeof(a)); cin>>n>>m; for(i=1;i<=n;i++) for(j=1;j<=m;j++) cin>>c[i][j]; q[0][0]=1; q[0][1]=1; a[1][1]=0; pq=0; nq=1; while(pqa[i][j]+1)) { a[ni][nj]=a[i][j]+1; q[nq][0]=ni; q[nq][1]=nj; nq++; } } pq++;} int maxi=0; for(i=1;i<=n;i++) for(j=1;j<=m;j++) if(a[i][j]>maxi&&(i==1 || j==1 || i==n || j==m)) maxi=a[i][j]; cout<