#include <bits/stdc++.h>

using namespace std;
const int N = 22, D[][2] = {
		{0,  1},
		{1,  0},
		{-1, 0},
		{0,  -1}
};
int n, m;
bool vis[N][N];
char s[N][N];
bool valid(int x, int y) {
	return 0 <= x && x < n && 0 <= y && y < m && s[x][y] == '.' && !vis[x][y]++;
}
int bfs(int i, int j) {
	queue<pair<int, int>> q;
	q.push({i, j});
	memset(vis, 0, sizeof vis);
	vis[i][j] = true;
	int level = 0;
	while (q.size()) {
		int sz = q.size();
		while (sz--) {
			auto cur = q.front();
			q.pop();
			for (int d = 0; d < 4; ++d) {
				int x = cur.first + D[d][0];
				int y = cur.second + D[d][1];
				if (valid(x, y)) {
					q.push({x, y});
				}
			}
		}
		++level;
	}
	return level - 1;
}
int main() {
//	freopen("input.in", "r", stdin);
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; ++i)
		scanf("%s", s[i]);
	int res = -1;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (s[i][j] == '.') {
				res = max(res, bfs(i, j));
			}
		}
	}
	printf("%d\n", res);
	return 0;
}


