#include <bits/stdc++.h>
using namespace std;
bool g[22][22];

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; ++i){
		for (int j = 0; j < w; ++j){
			char c;
			cin >> c;
			g[i][j] = (c == '.');
		}
	}
	vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};
	int ans = 0;
	queue<pair<int, int>> q;
	for (int xx = 0; xx < h; ++xx){
		for (int yy = 0; yy < w; ++yy){
			if (!g[xx][yy]) continue;
			vector<vector<int>> d(h + 1, vector<int>(w + 1, -1));
			d[xx][yy] = 0;
			q.push({xx, yy});
			while (q.size()){
				int x = q.front().first, y = q.front().second;
				q.pop();
				for (int i = 0; i < 4; ++i){
					int nx = x + dx[i], ny = y + dy[i];
					if (nx < 0 || nx > h || ny < 0 || ny > w) continue;
					if (!g[nx][ny]) continue;
					if (d[nx][ny] > -1) continue;
					d[nx][ny] = d[x][y] + 1;
					ans = max(ans, d[nx][ny]);
					q.push({nx, ny});
				}
			}

		}
	}
	cout << ans;
	return 0;
}

