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

const int dx[] = { 0,1,0,-1 };
const int dy[] = { -1,0,1,0 };

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	auto bfs = [&](int a, int b) {
		vector<vector<int>> ans(h, vector<int>(w));
		vector<vector<bool>> vi(h, vector<bool>(w));
		queue<P> que;
		int j_res = 0;
		que.emplace(a, b);
		vi[a][b] = true;
		while (que.size()) {
			P p = que.front(); que.pop();
			rep(i, 4) {
				int nx = p.first + dx[i], ny = p.second + dy[i];
				if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
				if (s[nx][ny] == '#') continue;
				if (vi[nx][ny]) continue;
				vi[nx][ny] = true;
				ans[nx][ny] = ans[p.first][p.second] + 1;
				j_res = max(j_res, ans[nx][ny]);
				que.emplace(nx, ny);
			}
		}
		return j_res;
	};
	int ans = 0;
	rep(i, h)rep(j, w) {
		if (s[i][j] == '#') continue;
		ans = max(ans, bfs(i, j));
	}
	cout << ans << endl;
	return 0;
}
