#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const int di[4] = { -1,0,1,0 };
const int dj[4]= { 0,-1,0,1 };

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	int ans = 0;
	rep(si, h)rep(sj, w) {
		if (s[si][sj] == '#')continue;
		vector<vector<int>> dist(h, vector<int>(w, INF));
		queue<P> q;
		if (dist[si][sj] == INF) {
			dist[si][sj] = 0;
			q.push(P(si, sj));
		}
		while (!q.empty()) {
			int i = q.front().first;
			int j = q.front().second;
			q.pop();
			rep(dir, 4) {
				int ni = i + di[dir];
				int nj = j + dj[dir];
				if (ni < 0 || ni >= h || nj < 0 || nj >= w)continue;
				if (s[ni][nj] == '#')continue;
				if (dist[ni][nj] == INF) {
					dist[ni][nj] = dist[i][j] + 1;
					q.push(P(ni, nj));
				}
			}
		}
		rep(i, h)rep(j, w) {
			if (dist[i][j] == INF)continue;
			ans = max(ans, dist[i][j]);
		}
	}

	cout << ans << endl;
}