#include <bits/stdc++.h>
using namespace std;

int h, w, vis[20][20];
string gr[20];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> h >> w;
	for(int i = 0; i < h; i++) cin >> gr[i];
	int mx = 0;
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++){
			if(gr[i][j] == '#') continue;
			for(int k = 0; k < h; k++)
				for(int l = 0; l < w; l++) vis[k][l] = -1;
			queue<tuple<int, int, int>> que;
			que.push(make_tuple(i, j, 0));
			while(!que.empty()){
				int a, b, c;
				tie(a, b, c) = que.front();
				que.pop();
				if(vis[a][b] != -1) continue;
				vis[a][b] = c;
				int ii[] = {-1, 0, 1, 0}, jj[] = {0, -1, 0, 1};
				for(int k = 0; k < 4; k++)
					if(a + ii[k] >= 0 && a + ii[k] < h && b + jj[k] >= 0 && b + jj[k] < w && vis[a + ii[k]][b + jj[k]] == -1 && gr[a + ii[k]][b + jj[k]] == '.') que.push(make_tuple(a + ii[k], b + jj[k], c + 1));
			}
			for(int k = 0; k < h; k++)
				for(int l = 0; l < w; l++) mx = max(mx, vis[k][l]);
		}
	cout << mx << "\n";
	return 0;
}