#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const int fx[4]={1,-1,0,0},fy[4]={0,0,1,-1};
struct node
{
	int x,y;
};
int n,m,ans=0;
int d[25][25];
char p[25][25];
bool vis[25][25];
queue<node> q;
int main()
{
	memset(p,0x3f,sizeof(p));
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	for(int j=0;j<m;j++)
	cin>>p[i][j];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(p[i][j]=='#') continue;
			memset(d,0,sizeof(d));
			memset(vis,0,sizeof(vis));
			q.push((node){i,j});
			vis[i][j]=1;
			while(!q.empty())
			{
				node no=q.front();
				q.pop();
				for(int k=0;k<4;k++)
				{
					int nx=no.x+fx[k],ny=no.y+fy[k];
					if(nx<n&&ny<m&&nx>=0&&ny>=0&&p[nx][ny]=='.'&&!vis[nx][ny])
					{
						vis[nx][ny]=1;
						d[nx][ny]=d[no.x][no.y]+1;
						ans=max(d[nx][ny],ans);
						q.push((node){nx,ny});
					}
				}
			}
		}
	}
	cout<<ans;
	return 0;
}