#include <bits/stdc++.h>
#include <math.h>

using namespace std;

long long inf=1000000007;
int h,w;
vector<string> maze(20);
int ans=-1;

void bfs(int sx,int sy){
	if(maze.at(sy).at(sx)=='#') return;

	vector<vector<int>> dist(h,vector<int>(w,-1));
	dist.at(sy).at(sx)=0;
	queue<pair<int,int>> que;
	que.push(make_pair(sx,sy));

	while(!que.empty()){
		int x=que.front().first;
		int y=que.front().second;
		que.pop();

		vector<int> dx={1,0,0,-1},dy={0,-1,1,0};

		for(int i=0;i<4;i++){
			int px=x+dx.at(i);
			int py=y+dy.at(i);
			if(px<0 || px>=w || py<0 || py>=h || maze.at(py).at(px)=='#' || dist.at(py).at(px)!=-1) continue;

			dist.at(py).at(px)=dist.at(y).at(x)+1;
			que.push(make_pair(px,py));
			ans=max(ans,dist.at(py).at(px));
		}
	}
}

int main(){
	cin>>h>>w;

	for(int i=0;i<h;i++){
		cin>>maze.at(i);
	}

	for(int sx=0;sx<w;sx++){
		for(int sy=0;sy<h;sy++){
			bfs(sx,sy);
		}
	}

	cout<<ans<<endl;

	return 0;
}
