from collections import deque
H, W = map(int, input().split())
s = ["#"*(W+2)] + ["#" + input() + "#" for _ in range(H)] + ["#"*(W+2)]
DH, DW = [0, 0, 1, -1], [1, -1, 0, 0]

def bfs(start):
	que = deque([start])
	dist = [[-1 for _ in range(W+2)] for _ in range(H+2)]
	dist[start[0]][start[1]] = 0
	num = 0

	while que:

		label = que.pop()
		h, w = label[0], label[1]
		
		for dh, dw in zip(DH, DW):
			hh, ww = h+dh, w+dw
			if s[hh][ww] == "." and dist[hh][ww] < 0:
				que.appendleft((hh, ww))
				dist[hh][ww] = dist[h][w] + 1
				num = max(num, dist[hh][ww])

	return num

ans = 0
for h in range(1, H+1):
	for w in range(1, W+1):
		if s[h][w] == ".":
			ans = max(ans, bfs((h, w)))
print(ans)