#include<bits/stdc++.h>
#define re register
using namespace std;
int n,m,dis[22][22],ans;
char mp[22][22];
inline bool check(re int x,re int y){
	if(x<1||x>n||y<1||y>m)return 0;
	if(mp[x][y]=='#')return 0;
	if(dis[x][y])return 0;
	return 1;
}
queue <int> q;
inline void bfs(re int x,re int y){
	q.push(x);
	q.push(y);
	while(!q.empty()){
		x=q.front();q.pop();
		y=q.front();q.pop();
		if(check(x+1,y))dis[x+1][y]=dis[x][y]+1,q.push(x+1),q.push(y);
		if(check(x-1,y))dis[x-1][y]=dis[x][y]+1,q.push(x-1),q.push(y);
		if(check(x,y+1))dis[x][y+1]=dis[x][y]+1,q.push(x),q.push(y+1);
		if(check(x,y-1))dis[x][y-1]=dis[x][y]+1,q.push(x),q.push(y-1);
	}
}
signed main(){
scanf("%d%d",&n,&m);
for(re int i=1;i<=n;++i)scanf("%s",mp[i]+1);
for(re int i=1;i<=n;++i){
	for(re int j=1;j<=m;++j){
		if(mp[i][j]=='.'){
	
		memset(dis,0,sizeof(dis));
		dis[i][j]=1;
		bfs(i,j);
		for(re int ii=1;ii<=n;++ii){
			for(re int jj=1;jj<=m;++jj){
				ans=max(ans,dis[ii][jj]);
			}
		}	}
	}
}
cout<<ans-1;
	}

