from queue import Queue
H, W = map(int, input().split())
S = [input() for _ in range(H)]
ans = 0

for h in range(H):
    for w in range(W):
        if S[h][w] != '.':
            continue
        q = Queue()
        seen = [[False]*W for _ in range(H)]
        q.put((h, w, 0))
        seen[h][w] = True
        while not q.empty():
            h, w, d = q.get()
            for nh, nw in [(h+1, w), (h, w+1), (h-1, w), (h, w-1)]:
                if nh < 0 or nw < 0 or nh >= H or nw >= W:
                    continue
                if not seen[nh][nw] and S[nh][nw] == '.':
                    q.put((nh, nw, d+1))
                    seen[nh][nw] = True
                    ans = max(d+1, ans)
print(ans)
