// ABC 151-D
// 2020.1.12 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void ins(char *s) { // 文字列の入力　スペース以下の文字で入力終了
	do *s = gc();
	while (*s++ > ' ');
	*(s-1) = 0;
}

int H, W;
char map[22][22];
char vis[22][22];
int ans

#define MAX 1000000
typedef struct { int r, c; int s; } Q;
Q q[MAX+5]; int top, end;
int mv[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};

void bfs(int r0, int c0) {
	int i, r, c, s, rr, cc, ma;

	memset(vis, 0, sizeof(vis));
	top = 0, end = 1;
	q[0].r = r0, q[0].c = c0, q[0].s = 0;
	vis[r0][c0] = 1;
	while (top != end) {
		r = q[top].r, c = q[top].c, s = q[top++].s;
		if (s > ans) ans = s;
		for (i = 0; i < 4; ++i) {
			rr = r + mv[i][0], cc = c + mv[i][1];
			if (map[rr][cc] == '.' && vis[rr][cc] == 0 &&
				rr >= 0 && rr < H && c >= 0 && c < W) {
				vis[rr][cc] = 1;
				q[end].r = rr, q[end].c = cc, q[end++].s = s+1;
			}
		}
	}
}

int main()
{
	int r, c;
	
	H = in(), W = in();
	for (r = 0; r < H; ++r) ins(map[r]);
	for (r = 0; r < H; ++r) for (c = 0; c < W; ++c) {
		if (map[r][c] == '.') bfs(r, c);
	}
	printf("%d\n", ans);
	return 0;
}
