#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
int h,w;
int arr[25][25];
int dy[4]={0,0,1,-1};
int dx[4]={1,-1,0,0};
int solve(int a,int b){
	int ret = 0;
	bool visited[25][25]={false};
	queue<pair<pi,int> >q;
	q.push(make_pair(pi(a,b),0));
	visited[a][b] = true;
	while(!q.empty()){
		int y = q.front().first.first;
		int x = q.front().first.second;
		int d = q.front().second;
		ret = max(ret,d);
		q.pop();
		for(int i=0; i<4; i++){
			int yy = y+dy[i];
			int xx = x+dx[i];
			if(yy<1 || yy>h || xx<1 || xx>w) continue;
			if(visited[yy][xx] || arr[yy][xx]) continue;
			visited[yy][xx] = true;
			q.push(make_pair(pi(yy,xx),d+1));
		}
	}
	return ret;
}
int main(){
	cin>>h>>w;
	for(int i=1; i<=h; i++){
		string s;
		cin>>s;
		for(int j=0; s[j]; j++){
			if(s[j]=='#') arr[i][j+1] = 1;
		}
	}
	int ret = 0;
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++){
			if(arr[i][j]==0){
				ret = max(ret,solve(i,j));
			}
		}
	}
	cout<<ret;
}