#include <iostream>
#include <algorithm>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int H, W;
char s[20][20];
bool visited[20][20];

typedef struct location {
	int x, y, c;
} L;

int bfs(int x, int y) {
	rep(i, H) rep(j, W) visited[i][j] = false;

	queue<L> q;
	q.push(L{ x, y, 0 });

	int c = 0;
	while (!q.empty()) {
		L tmp = q.front();
		q.pop();
		x = tmp.x;
		y = tmp.y;
		c = tmp.c;

		if (s[x][y] == '#' || visited[x][y]) continue;
		visited[x][y] = true;

		if (x + 1 < H && s[x + 1][y] == '.') q.push(L{ x + 1, y, c + 1});
		if (0 <= x - 1 && s[x - 1][y] == '.') q.push(L{ x - 1, y, c + 1});
		if (y + 1 < W && s[x][y + 1] == '.') q.push(L{ x, y + 1, c + 1});
		if (0 <= y - 1 && s[x][y - 1] == '.') q.push(L{ x, y - 1, c + 1});
	}
	return max(0, c - 1);
}

int main() {
	cin >> H >> W;

	int ans = 0;

	rep(i, H) rep(j, W) cin >> s[i][j];
	rep(i, H) rep(j, W) ans = max(ans, bfs(i, j));

	cout << ans << endl;

	return 0;
}