// D - Maze Master
#include <bits/stdc++.h>

using namespace std;

#define	INF	100000000

void floyd(vector<vector<int> > &cost)
{
	for (int k = 0, n = cost.size(); k < n; k++)
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
}


int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	for (int i = 0; i < h; i++) cin >> s[i];
	vector<vector<int> > g(h * w, vector<int>(h * w, INF));
	for (int i = 0; i < g.size(); i++) g[i][i] = 0;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) {
			if (s[i][j] != '.') continue;
			int u = i * w + j;
			if (i + 1 < h && s[i + 1][j] == '.')
				g[u][u + w] = g[u + w][u] = 1;
			if (j + 1 < w && s[i][j + 1] == '.')
				g[u][u + 1] = g[u + 1][u] = 1;
		}
	floyd(g);
	int ans = 0;
	for (int i = 0; i < g.size(); i++)
		for (int j = 0; j < g.size(); j++)
			if (g[i][j] < INF)
				ans = max(ans, g[i][j]);
	cout << ans << endl;

	return 0;
}
