#include #include using namespace std; const int N=3010,dx[5]={0,1,-1,0,0},dy[5]={0,0,0,1,-1}; char s[N][N]; bool vis[N][N]; struct P { int x,y,d; }; int main() { //freopen("refuge.in","r",stdin); //freopen("refuge.out","w",stdout); int n,m; scanf("%d %d",&n,&m); for(int i=0;i<=m+1;i++) s[0][i]=s[n+1][i]='.'; for(int i=1;i<=n;i++) scanf("%s",s[i]+1),s[i][0]=s[i][m+1]='.'; queue

q; for(int i=0;i<=n+1;i++) for(int j=0;j<=m+1;j++) if(s[i][j]=='.') q.push((P){i,j,0}),vis[i][j]=true; int ans=0; while(!q.empty()) { P p=q.front(); q.pop(); for(int i=1;i<=4;i++) { int xx=p.x+dx[i],yy=p.y+dy[i]; if(xx>=0&&xx<=n+1&&yy>=0&&yy<=m+1&&!vis[xx][yy]) q.push((P){xx,yy,p.d+1}),vis[xx][yy]=true,ans=max(ans,p.d); } } printf("%d",ans); return 0; }