#include <bits/stdc++.h>
using namespace std;
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using vl = vector<long long>;
using P = pair<long long,long long>;

int main(){
	ll h,w; cin >> h >> w;
	char s[20][20];
	rep(i,h){
		rep(j,w)cin >> s[i][j];
	}
	ll dist[20][20];
	queue<P> que;
	ll ans = 0;
	vl dx = {0,1,0,-1};
	vl dy = {1,0,-1,0};
	rep(i,h){
		rep(j,w){
			if(s[i][j] == '#')continue;
			rep(p,h){
				rep(q,w)dist[p][q] = -1;
			}
			que.push(make_pair(i,j));
			dist[i][j] = 0;
			while(!que.empty()){
				P v = que.front();
				que.pop();
				rep(k,4){
					ll y = v.first+dy[k]; ll x = v.second+dx[k];
					if(y < 0 || y >= h || x < 0 || x >= w)continue;
					if(dist[y][x] != -1 || s[y][x] == '#')continue;
							dist[y][x] = dist[v.first][v.second] + 1;
							que.push(make_pair(y,x));
						
					
				}
			}
			rep(p,h){
				rep(q,w)ans = max(ans,dist[p][q]);
			}
		}
	}
	cout << ans << endl;
}