H, W = map(int, input().split())
S = []

def bfs(a, b):
	Q = [[a, b, 0]]
	d_lst = [[4000 for _ in range(W)] for _ in range(H)]
	while Q:
		cur = Q.pop(0)
		y, x, d = cur[0], cur[1], cur[2]
		if S[y][x] == "#": continue
		d_lst[y][x] = min(d_lst[y][x], d)
		
		if x > 0 and d + 1 < d_lst[y][x - 1]:
			Q.append([y, x - 1, d + 1])
		if x < W - 1 and d + 1 < d_lst[y][x + 1]:
			Q.append([y, x + 1, d + 1])
		if y > 0 and d + 1 < d_lst[y - 1][x]:
			Q.append([y - 1, x, d + 1])
		if y < H - 1 and d + 1 < d_lst[y + 1][x]:
			Q.append([y + 1, x, d + 1])
	
	ans = 0
	for i in range(H):
		for j in range(W):
			if S[i][j] == "#": continue
			ans = max(ans, d_lst[i][j])
	return ans
		

for i in range(H):
	tmp = list(map(str, input()))
	S.append(tmp)
	
res = 0
for i in range(H):
	for j in range(W):
		if S[i][j] == "#": continue
		res = max(res, bfs(i, j))
		
print(res)