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

char s[25][25];

int dir[4][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};
int d[25][25] = {-1};
const int DIR = 4;

int main() {
	int h, w; cin >> h >> w;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> s[i][j];
		}
	}

	int ans = 0;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {

			if (s[i][j] == '#') continue;

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

			// vector<vector<bool>> vis(h, vector<bool>(w, false));
			memset(d, -1, sizeof(d));
			d[i][j] = 0;

			while (!q.empty()) {
				auto p = q.front(); q.pop();

				int xs = p.first;
				int ys = p.second;

				for (int i = 0; i < DIR; i++) {
					int dx = xs + dir[i][0];
					int dy = ys + dir[i][1];
					if (dx < 0 || dx >= h || dy < 0 || dy >= w || ~d[dx][dy] || s[dx][dy] == '#')
						continue;

					d[dx][dy] = d[xs][ys] + 1;
					ans = std::max(ans, d[dx][dy]);
					q.push(make_pair(dx, dy));
				}
			}
		}
	}

	cout << ans;
}