#include<cstdio>
#include<cstring>
const int fx[4]={0,1,0,-1};
const int fy[4]={1,0,-1,0};
const int N=20+10;
int f[N][N],n,m,ans;
inline int ma(int a,int b){return a>b?a:b;}
char s[N][N];
void dfs(int x,int y,int sum)
{
	if(x>n||x<1||y>m||y<1||s[x][y]=='#')return;
	if(f[x][y]<=sum)return;
	f[x][y]=sum;
	for(int i=0;i<4;i++)
		dfs(fx[i]+x,fy[i]+y,sum+1);
	return;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(s[i][j]!='#')
			{
				memset(f,0x3f,sizeof(f));
				dfs(i,j,0);
				for(int x=1;x<=n;x++)
					for(int y=1;y<=n;y++)
						if(f[x][y]!=0x3f3f3f3f)ans=ma(ans,f[x][y]);
			}
	printf("%d",ans);
	return 0;
}