#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#define Inf 0x7fffffff
using namespace std;
char maze[850][850];
int mov[4][2]={0,1,0,-1,1,0,-1,0};
struct node
{
int x,y;
int step;
};
bool vis[850][850];
node bfs(int a,int b)
{
int i,x,y;
memset(vis,false,sizeof(vis));
node ans;
ans.x=a,ans.y=b,ans.step=0;
node ini;
ini.x=a,ini.y=b,ini.step=0;
queue<node> q;
q.push(ini);
vis[a][b]=true;
while(!q.empty())
{
ini=q.front();
q.pop();
if(ans.step<ini.step)
ans=ini;
for(int i=0;i<4;i++)
{
int x=ini.x+mov[i][0];
int y=ini.y+mov[i][1];
int s=ini.step+1;
node tmp;tmp.x=x;tmp.y=y;tmp.step=s;
if(!vis[x][y]&&maze[x][y]!='#')
{
vis[x][y]=true;
q.push(tmp);
}
}
}
return ans;
}
int main()
{
int m,n,a,b;
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(~scanf("%d %d\n",&m,&n))
{
memset(maze,'#',sizeof(maze));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%c",&maze[i][j]);
if(maze[i][j]=='.')
a=i,b=j;
}
getchar();
}
node p1=bfs(a,b);
node p2=bfs(p1.x,p1.y);
//cout<<p2.x<<" "<<p2.y<<endl;
printf("%d\n",p2.step);
}
return 0;
}