#include<bits/stdc++.h>
using namespace std;
int n,m,d[30][30],f[30][30],ans;
char ch;
void dfs(int x,int y,int k)
{
	if(!f[x][y])return;
	if(d[x][y]<=k)return;else d[x][y]=k;
	dfs(x-1,y,k+1);dfs(x+1,y,k+1);
	dfs(x,y-1,k+1);dfs(x,y+1,k+1);
}
int mx()
{
	int mxx=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(d[i][j]^d[0][0])mxx=max(mxx,d[i][j]);
	return mxx;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(cin>>ch,ch=='.')f[i][j]=1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			memset(d,0x7f,sizeof(d));
			dfs(i,j,0);
			ans=max(ans,mx());
		}
	printf("%d\n",ans);
	return 0;
}