#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair

char s[25][25];
vector<long long> dx={1,0,0,-1};
vector<long long> dy={0,1,-1,0};

int main() {
	ll h,w;
	cin >> h >> w;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			cin >> s[i][j];
		}
	}
	ll ans=0;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			if(s[i][j]=='#') continue;
			vector<vector<ll>> dist(25, vector<ll>(25,-1));
			queue<pair<ll,ll>> que;
			dist[i][j]=0;
			que.push(make_pair(i,j));
			while(!que.empty()){
				auto v=que.front();
				que.pop();
				for(ll k=0;k<4;k++){
					ll nx=v.fi+dx[k];
					ll ny=v.se+dy[k];
					if(nx<0||nx>=h||ny<0||ny>=w) continue;
					if(s[nx][ny]=='#') continue;
					if(dist[nx][ny]!=-1) continue;
					dist[nx][ny]=dist[v.fi][v.se]+1;
					ans=max(ans,dist[nx][ny]);
					que.push(make_pair(nx,ny));
				}
			}
		}
	}
	cout<<ans<<endl;
}
