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

vector<int> dx = { -1,0,0,1 };
vector<int> dy = { 0,-1,1,0 };

int main() {
	ll h, w;
	cin >> h >> w;
	vector<string> v;
	string tmp(w + 2, '#');
	v.push_back(tmp);
	ll ans = 0;
	for (ll i = 0; i < h; ++i) {
		string s;
		cin >> s;
		v.push_back("#" + s + "#");
	}
	v.push_back(tmp);
	for (ll i = 1; i <= h; ++i) {
		for (ll j = 1; j <= w; ++j) {
			if (v[i][j] == '#')continue;
			vector<vector<bool>> visited(h + 2, vector<bool>(w + 2, false));
			queue<pair<pair<ll, ll>, ll>> q;
			q.push({ {i,j},0 });
			while (!q.empty()) {
				auto p = q.front();
				q.pop();
				if (visited[p.first.first][p.first.second])continue;
				ans = max(ans, p.second);
				visited[p.first.first][p.first.second] = true;
				for (ll k = 0; k < 4; ++k) {
					if (v[p.first.first + dx[k]][p.first.second + dy[k]] == '.') {
						q.push({ {p.first.first + dx[k],p.first.second + dy[k]},p.second + 1 });
					}
				}
			}
			
		}
	}
	cout << ans << endl;
}
