#include <bits/stdc++.h>

using namespace std;

const int N = 25;

int n, m;
char mat[N][N];
int dx[] = {1,-1, 0, 0};
int dy[] = {0, 0,-1, 1};

int dist[N][N];

int bfs(int x, int y) {
	memset(dist, -1, sizeof dist);
	int ans = 0;
	dist[x][y] = 0;
	queue<pair<int, int>> q;
	q.emplace(x, y);
	while(!q.empty()) {
		tie(x, y) = q.front(); q.pop();
		ans = max(ans, dist[x][y]);
		for(int i = 0; i < 4; i++) {
			int xx = x + dx[i];
			int yy = y + dy[i];
			if(xx < 0 or xx >= n) continue;
			if(yy < 0 or yy >= m) continue;
			if(mat[xx][yy] == '#') continue;
			if(dist[xx][yy] != -1) continue;
			dist[xx][yy] = dist[x][y] + 1;
			q.emplace(xx, yy);
		}
	}
	return ans;
}

int main() {
	scanf("%d %d", &n, &m);

	for(int i = 0; i < n; i++) scanf(" %s", mat[i]);

	int ans = 0;
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) if(mat[i][j] == '.')
		ans = max(ans, bfs(i, j));
	printf("%d\n", ans);
}
