//Maze Master
#include <bits/stdc++.h>
using namespace std;

int h, w, ans = 0;	char vis[50][50] = {0};
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

int bfs(int x, int y) {
	int dist[h][w], mx = 0;		memset(dist, -1, sizeof(dist));
	queue <pair <int, int>> q;
	q.push({x, y});		dist[x][y] = 0;
	while (!q.empty()) {
		pair<int, int> z = q.front();
		int u = z.first;	int v = z.second;
		q.pop();
		for (int i = 0; i < 4; i++) {
			int nu = u + dx[i], nv = v + dy[i];
			if (0 <= nu && nu < h && 0 <= nv && nv < w) {	
				if (vis[nu][nv] == '.' && dist[nu][nv] == -1) {
					dist[nu][nv] = dist[u][v] + 1;
					q.push({nu, nv});
				}
			}
		}
	}
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			mx = max(mx, dist[i][j]);
	return mx;
}

int main() {
	cin >> h >> w;
	char temp;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			cin >> vis[i][j];
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			if (vis[i][j] == '.')
				ans = max(ans, bfs(i, j));
	cout << ans << endl;
	return 0;
}