import sys
from collections import deque
H, W = map(int, input().split())
ROAD = set()
for h in range(H):
    for w, c in enumerate(sys.stdin.readline()):
        if c == ".":
            ROAD.add((h, w))

todo = deque()
done = set()
ans = 0
for s in ROAD:
    done.clear()
    todo.append((s, 0))
    while todo:
        p, count = todo.popleft()
        ans = max(ans, count)
        done.add(p)
        ncount = count + 1
        for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            np = (p[0] + dh, p[1] + dw)
            if not np in ROAD or np in done:
                continue
            todo.append((np, ncount))
print(ans)