#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 500005;

int n, m, i, j, k, l, d[20][20], tab[20][20], maxx;
char t[20];
queue<ii> q;
ii w;

int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};

bool ok(int a, int b) {
	return a >= 0 && a < n && b >= 0 && b < m && d[a][b] == -1 && !tab[a][b];
}

int main() {
scanf("%d %d", &n, &m);
for (i=0;i<n;i++) {
	scanf("%s", t);
	for (j=0;j<m;j++) tab[i][j] = (t[j] == '#');
}
for (i=0;i<n;i++) for (j=0;j<m;j++) if (!tab[i][j]) {
	for (k=0;k<n;k++) for (l=0;l<m;l++) d[k][l] = -1;
	q.push(ii(i, j));
	d[i][j] = 0;
	while (!q.empty()) {
		w = q.front();
		q.pop();
		for (k=0;k<4;k++) if (ok(w.first + dx[k], w.second + dy[k])) {
			d[w.first + dx[k]][w.second + dy[k]] = d[w.first][w.second] + 1;
			q.push(ii(w.first + dx[k], w.second + dy[k]));
		}
	}
	for (k=0;k<n;k++) for (l=0;l<m;l++) maxx = max(maxx, d[k][l]);
}
printf("%d\n", maxx);
}