from collections import deque
H, W = map(int, input().split())
S = [input() + "#" for _ in range(H)]
S.append("#" * (W + 1))
paths = [(h, w) for h in range(H) for w in range(W) if S[h][w] == "."]

ans = 0
todo = deque()
done = [[False] * W for _ in range(H)]
for sh, sw in paths:
    done[sh][sw] = True
    for gh, gw in paths:
        if done[gh][gw]:
            continue
        todo.append((0, sh, sw))
        pathed = [[False] * W for _ in range(H)]
        while todo:
            cnt, h, w = todo.popleft()
            cnt += 1
            for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                nh = h + dh
                nw = w + dw
                if nh == gh and nw == gw:
                    if ans < cnt:
                        ans = cnt
                    todo.clear()
                    break
                elif S[nh][nw] == "." and not pathed[nh][nw]:
                    todo.append((cnt, nh, nw))
            pathed[h][w] = True
print(ans)