#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[25][25];
int X[25], Y[25]; //所有.的坐标
bool vis[25][25];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct PP {
	int x, y;
	int res;
} s, q;
queue <PP> qua;
int cnt, ans;

void Init() {
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) {
		scanf("%s", a[i] + 1);
		for(int j = 1; j <= m; j++) {
			if(a[i][j] == '.') {
				X[++cnt] = i;
				Y[cnt] = j;
			}
		}
	}
}

int Bfs(int x, int y, int ex, int ey) {
	int x, y0, res;
	s.x = x, s.y = y, s.res = 0;
	qua.push(s);
	while(!qua.empty()) {
		s = qua.front();
		qua.pop();
		if(s.x == ex && s.y == ey) return s.res;
		for(int i = 0; i < 4; i++) {
			x0 = s.x + dx[i], y0 = s.y + dy[i];
			res = s.res + 1;
			if(vis[x0][y0] || x0 < 1 || x0 > n || y0 < 1 || y0 > m || a[x0][y0] == '#') continue;
			vis[x0][y0] = 1;
			q.x = x0, q.y = y0, q.res = res;
			qua.push(q);
		}
	}
}

int main() {
	Init();
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(a[i][j] == '.') {
				for(int k = 1; k <= cnt; k++) {
					memset(vis, 0, sizeof(vis));
					while(!qua.empty()) qua.pop();
					int tmp = Bfs(i, j, X[k], Y[k]); // (i, j) -> (X[k], Y[k])的最短路径
					//printf("%d %d -> %d %d: %d\n", i, j, X[k], Y[k], tmp);
					ans = max(ans, tmp);
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}