#include <iostream>
using namespace std;
#define rep(i, n) for (i = 0; i < n; i++)
int h, w, n, mx, d[405][405];
char b[25][25];
void f(int p, int q) { d[p][q] = d[q][p] = 1; }
int main() {
	int i, j, k;
	cin >> h >> w;
	rep(i, h) cin >> b[i];
	n = h * w;
	rep(i, n) rep(j, n) if (i != j) d[i][j] = 1e9;
	rep(i, h) rep(j, w) {
		if (b[i][j] == '.' && b[i][j + 1] == '.')
			f(i * w + j, i * w + j + 1);
		if (b[i][j] == '.' && b[i + 1][j] == '.')
			f(i * w + j, (i + 1) * w + j);
	}
	rep(k, n) rep(i, n) rep(j, n) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); }
	rep(i, n) rep(j, n) if (d[i][j] < 1e9) mx = max(mx, d[i][j]);
	cout << mx;
}
