#include<cstdio>
#include<algorithm>
 
using namespace std;

int n,m,f[422][422]; 
char s[21][21];

int turn(int x,int y)
{
	return (x-1)*m+y;
}

int main()
{
//	freopen("data.txt","r",stdin);
//	freopen("my.txt","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) scanf("%s",s[i]+1);
	int t=n*m;
	for(int i=1;i<=t;++i)
		for(int j=1;j<=t;++j)
			f[i][j]=1e9;
	int u,v;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
		{
			u=turn(i,j);
			if(s[i][j]=='#')
			{
				if(u>m) f[u][u-m]=1e9;
				f[u][u+m]=f[u][u]=f[u][u-1]=f[u][u+1]=1e9;
				continue;
			}
			f[u][u]=0;
			if(i>1 && s[i-1][j]=='.') f[u][u-m]=1;
			if(i<n && s[i+1][j]=='.') f[u][u+m]=1;
			if(j>1 && s[i][j-1]=='.') f[u][u-1]=1;
			if(j<m && s[i][j+1]=='.') f[u][u+1]=1;
		}
	for(int k=1;k<=t;++k)
		for(int i=1;i<=t;++i)
			for(int j=1;j<=t;++j)
				if(f[i][k]<1e9 && f[k][j]<1e9) f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
	int ans=0;
	for(int i=1;i<=t;++i)
		for(int j=1;j<=t;++j)
			if(f[i][j]<1e9) ans=max(ans,f[i][j]);
	printf("%d",ans);
}
