#include<bits/stdc++.h>
using namespace std;
int h,w,vis[30][30],a[30][30],ans=-1;
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
void bfs(int x,int y) {
	queue<int> num;
	queue< pair<int,int> > q;
	memset(vis,0,sizeof(vis));
	vis[x][y]=1;
	q.push(make_pair(x,y));
	num.push(0);
	while(!q.empty()) {
		pair<int,int> f=q.front();q.pop();
		int tmp=num.front();num.pop();
		x=f.first,y=f.second;
		ans=max(ans,tmp);
		for(int i=0;i<4;++i) {
			int x1=x+dx[i],z1=y+dy[i];
			if(!a[x1][z1]&&!vis[x1][z1]) {
				vis[x1][z1]=1;
				q.push(make_pair(x1,z1));
				num.push(tmp+1);
			}
		}
	}
}
int main()
{
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;++i) {
		string s;
		cin>>s;
		for(int j=1;j<=w;++j)
			if(s[j-1]=='#')
				a[i][j]=1;
	}
	for(int i=0;i<=h;++i) a[i][0]=a[i][w+1]=1;
	for(int i=0;i<=w;++i) a[0][i]=a[h+1][i]=1;
	for(int i=1;i<=h;++i)
		for(int j=1;j<=w;++j)
			if(!a[i][j])
				bfs(i,j);
	printf("%d",ans);
	return 0; 
}