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

const int dx[] = { -1,0,1,0 };
const int dy[] = { 0,-1,0,1 };
int H, W;
int f(int n, int m,vector<string> S) {
	vector<vector<int>> data(20, vector<int>(20)); 
	queue<pair<int, int>> q;
	q.emplace(n, m); 
	S[n][m] = '#';
	int ans = 0;
	while (!q.empty()) {
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
		//範囲内かつ0を4セット
		for (int l = 0; l < 4; ++l) {
			int x1 = x + dx[l];
			int y1 = y + dy[l]; 
			if ((0 <= x1) && (H > x1) && (0 <= y1) && (W > y1) && ('.' == S[x1][y1])) {
				S[x1][y1] = '#';
				data[x1][y1] = data[x][y] + 1;
				ans = max(ans, data[x][y] + 1);
				q.emplace(x1, y1);
			}
		}
	}
	return ans;
}

int main() {
	cin >> H >> W;
	vector<string> S(H);
	for (int n = 0; n < H; ++n) {
		cin >> S[n];
	}
	int ans = 0;
	for (int n = 0;n< H ;++n) {
		for (int m = 0;m<W;++m) {
			if ('#' != S[n][m]) {
				ans = max(ans, f(n,m, S));
			}
		}
	}
	cout << ans <<endl;
	return 0;
}