#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
char mp[25][25];
bool bj[25][25];
struct node{
	int x,y,dis;
};
int fx[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
void bfs(int nx,int ny){
	if(mp[nx][ny]=='#')return ;
	memset(bj,false,sizeof(bj));
	queue<node>q;
	q.push((node){nx,ny,0});
	bj[nx][ny]=1;
	while(!q.empty()){
		node now=q.front();
		q.pop();
//		cout<<now.x<<" "<<now.y<<endl;
		ans=max(ans,now.dis);
		for(int i=0;i<4;++i){
			int vx=now.x+fx[i][0],vy=now.y+fx[i][1];
			if(vx<=0||vx>n||vy<=0||vy>m||mp[vx][vy]=='#'||bj[vx][vy])continue;
			q.push((node){vx,vy,now.dis+1});
			bj[vx][vy]=true;
		}
	}
}
int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%s",mp[i]+1);
	for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)bfs(i,j);
	cout<<ans;
	return 0;
}
