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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;



int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int h, w;
	int ans = 0;
	cin >> h >> w;

	vector<string> mp(h);
	rep(i, 0, h) cin >> mp[i];

	rep(i, 0, h) rep(j, 0, w) if (mp[i][j] == '.') {
		vector<vi> dist(h, vi(w, 999));
		dist[i][j] = 0;

		queue<pair<int, int>> q;
		q.push({i, j});

		while (!q.empty()) {
			int a, b; tie(a, b) = q.front(); q.pop();
			const int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
			rep(d, 0, 4) {
				int na = a + dir[d][0], nb = b + dir[d][1];
				if (0 <= na && na < h && 0 <= nb && nb < w && dist[a][b] + 1 < dist[na][nb] && mp[na][nb] == '.') {
					dist[na][nb] = dist[a][b] + 1;
					ans = max(ans, dist[na][nb]);
					q.push({na, nb});
				}
			}
		}
	}

	cout << ans << endl;
}
