#include<bits/stdc++.h>
using namespace std;
int n,m;
char mat[22][22];

int q[100100][2];
bool book[22][22];
int dis[22][22];
int ans;
int st,ed;
bool check(int x,int y)
{
	if(x<1||y<1||x>n||y>m)return 0;
	if(mat[x][y]=='#')return 0;
	return 1;
}
int fl[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
void BFS(int x,int y)
{
	st=ed=0;
	q[++ed][0]=x;q[ed][1]=y;
	memset(book,0,sizeof(book));
	book[x][y]=1;
	memset(dis,0,sizeof(dis));
	int nx,ny;
	while(st<ed)
	{
		x=q[++st][0];y=q[st][1];
		ans=max(ans,dis[x][y]);
		for(int i=0;i<4;++i)
		{
			nx=x+fl[i][0];ny=y+fl[i][1];
			if(!check(nx,ny)||book[nx][ny])continue;
			dis[nx][ny]=dis[x][y]+1;
			q[++ed][0]=nx;q[ed][1]=ny;
			book[nx][ny]=1;
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%s",mat[i]+1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			if(mat[i][j]=='.')
				BFS(i,j);
	printf("%d\n",ans);
	return 0;
}
