#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define po pop_front
#define m(o) memset(o,-1,sizeof(o))
#define fo(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pi pair < int , int > 
const int b=22,dx[]={1,0,-1,0},dy[]={0,1,0,-1};
string in[b];
int far[b][b];
int n,m,ans=-1;
pi a;
int bfs()
{
	deque < pi > p;m(far);
	p.pb(a);
	far[a.first][a.second]=0;
	while(!p.empty())
	{
		pi now=p[0];
		p.po();
		int x=now.first,y=now.second;
		fo(i,4)
		{
			int xx=x+dx[i],yy=y+dy[i];
			if(xx<0||yy<0||yy>=m||xx>=n||in[xx][yy]=='#')	continue;
			if(far[xx][yy]==-1)
			{
				p.pb(mp(xx,yy));
				far[xx][yy]=far[x][y]+1;
			}
		}
	}
	int ans2=0;
	fo(i,n)
		fo(c,m)
			ans2=max(ans2,far[i][c]);
	return ans2;
}
int main()
{
	cin>>n>>m;
	fo(i,n)
		cin>>in[i];
	fo(i,n)
	{
		fo(c,m)
		{
			if(in[i][c]!='#')
			{
				a=mp(i,c);
				int now=bfs();
				ans=max(ans,now);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}