#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[25][25];
int X[25], Y[25]; //所有.的坐标
bool vis[25][25];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct PP {
	int x, y;
	int res;
} s, q;
queue <PP> qua;
int cnt, ans;

void Init() {
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) scanf(" %c", &a[i][j]);
	}
}

bool Chk(int x, int y) {
	if(int vis[x][y] || x < 1 || x > n || y < 1 || y > m || a[x][y] == '#') return false;
	return true;
}

int Bfs(int x, int y) {
	int res = 0;
	s.x = x, s.y = y, s.res = 0;
	vis[x][y] = 1;
	qua.push(s);
	while(!qua.empty()) {
		s = qua.front();
		qua.pop();
		if(s.x == ex && s.y == ey) return s.res;
		for(int i = 0; i < 4; i++) {
			q.x = s.x + dx[i], q.y = s.y + dy[i];
			if(!Chk(q.x, q.y)) continue;
			q.res = s.res + 1;
			vis[q.x][q.y] = 1;
			qua.push(q);
		}
	}
}

int main() {
	Init();
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(a[i][j] == '.') {
				for(int k = 1; k <= cnt; k++) {
					memset(vis, 0, sizeof(vis));
					while(!qua.empty()) qua.pop();
					int tmp = Bfs(i, j);
					ans = max(ans, tmp);
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}