#include <bits/stdc++.h>

#define FOR(i, n) for(int i = 0; i < n; i++) 

#define pow CHANGETHENAMESTUPID

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

char s[100][100];

void load() {
	int n, m; scanf("%d%d", &n, &m);
	FOR(i, n) scanf("%s", s[i]);
	auto bad = [&](int x, int y) {
		return x < 0 || x >= n || y < 0 || y >= m || s[x][y] == '#';
	};
	int dx[] = {1, -1, 0, 0};
	int dy[] = {0, 0, 1, -1};
	int maxi = 0;
	FOR(i, n) FOR(j, m) {
		if (bad(i, j)) continue;
		queue<int> Q;
		Q.push(i); Q.push(j);
		int bio[n][m];
		FOR(x, n) FOR(y, m) bio[x][y] = -1;
		bio[i][j] = 0;
		while (!Q.empty()) {
			int x = Q.front(); Q.pop();
			int y = Q.front(); Q.pop();
			FOR(k, 4) {
				int x_ = x + dx[k];
				int y_ = y + dy[k];
				if (bad(x_, y_)) continue;
				if (bio[x_][y_] == -1) {
					bio[x_][y_] = bio[x][y] + 1;
					maxi = max(maxi, bio[x_][y_]);
					Q.push(x_); Q.push(y_);
				}
			}
		}
	}
	printf("%d\n", maxi);
}

void solve() {

}

int main() {
	load();
	solve();
	return 0;
}
