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

const int N = 30;
const int dx[] = { 0, 0, 1, -1 };
const int dy[] = { 1, -1, 0, 0 };


char mp[N][N];
int dis[N][N];
queue< pair<int, int> > q;

int solve (int x, int y, int n, int m) {
	if (mp[x][y] == '#') return -1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			dis[i][j] = -1;
	dis[x][y] = 0;
	int ret = 0;
	q.push({ x, y });
	while (!q.empty()) {
		int ii = q.front().first;
		int jj = q.front().second;
		q.pop();
		ret = max(ret, dis[ii][jj]);
		for (int k = 0; k < 4; k++) {
			int i = ii + dx[k];
			int j = jj + dy[k];
			if (i < 1 || i > n || j < 1 || j > m || mp[i][j] == '#' || ~dis[i][j])
				continue;
			dis[i][j] = dis[ii][jj] + 1;
			q.push({ i, j });
		}
	}
	return ret;
}

int main (void) {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
		scanf("%s", mp[i] + 1);

	int ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			ans = max(ans, solve(i, j, n, m));
	printf("%d\n", ans);
}