import copy

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

def solve(start):
	flg = copy.deepcopy(flg_orig)
	q = [start]
	cnt = 0
	while q != []:
		cx, cy, cd  = q.pop(0)
		flg[cx][cy] = 1
		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] == 1:
				continue
			else:
				flg[nx][ny] = 1

			q.append([nx,ny,cd+1])
			cnt = max(cnt, cd+1)
	return cnt


flg_orig = [[0 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] = 1


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

print(ans)