#include <bits/stdc++.h>
using namespace std;
const int N = 25;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};

struct node{
	int x, y;
	int time;
} t, p;

char s[N][N];
bool ok[N][N];
queue<node> q;

int main()
{
	int h, w, res = 0;
	cin >> h >> w;
	for (int i = 0; i < h; i++)
		cin >> s[i];
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			if (s[i][j] == '.'){
				t.x = i; t.y = j; t.time = 0;
				q.push(t);	ok[i][j] = 1;
				while (!q.empty()){
					t = q.front(); q.pop();
					res = max(res, t.time);
					for (int i = 0; i < 4; i++){
						int nx = t.x + dx[i];
						int ny = t.y + dy[i];
						if (nx >= 0 && nx < h && ny >= 0 && ny < w && !ok[nx][ny] && s[nx][ny] == '.'){
							p.x = nx; p.y = ny; p.time = t.time + 1;
							ok[nx][ny] = 1;	q.push(p);
						}
					}
				}
				memset(ok, 0, sizeof(ok));
			}
		}
	}
	cout << res;
	return 0;
}