import copy

H, W = map(int, input().split())
S = [list(map(str, input())) for _ in range(H)]

def solve(sx,sy):
	flg = copy.deepcopy(flg_orig)
	flg[sx][sy] = 0
	q = [[sx,sy]]
	cnt = 0
	while q != []:
		cx, cy = q.pop(0)
		cd = flg[cx][cy]
		nps = [[cx+1,cy],[cx-1,cy],[cx,cy+1],[cx,cy-1]]
		for nx,ny in nps:
			if not (0 <= nx < H and 0 <= ny < W):
				continue
			if flg[nx][ny] == "#":
				continue
			if flg[nx][ny] <= cd+1:
				continue
			else:
				flg[nx][ny] = cd + 1

			q.append([nx,ny])

	cnt = 0
	for i in range(H):
		for j in range(W):
			if flg[i][j] == "#":
				continue
			else:
				cnt = max(cnt,flg[i][j])

	return cnt

INF = float("inf")
flg_orig = [[INF for _ in range(W)] for _ in range(H)]
for i in range(H):
	for j in range(W):
		if S[i][j] == "#":
			flg_orig[i][j] = "#"


ans = 0
for start_x in range(H):
	for start_y in range(W):
		tmp_cnt = solve(start_x, start_y)
		ans = max(ans, tmp_cnt)

print(ans)