from collections import deque

def solve():
    H, W = map(int, input().split())

    l = []
    for _ in range(H):
        l.append([0 if s=="." else 1 for s in input()])

    def dfs(sh, sw, gh, gw):
        q = deque([(sh, sw)])
        dist = [[10**12]*W for _ in range(H)]
        dist[sh][sw] = 0
        while q:
            h, w = q.popleft()
            for h1, w1 in [(h+1, w), (h, w+1), (h-1, w), (h, w-1)]:
                if not (0<=h1<H and 0<=w1<W):continue
                if l[h1][w1]:continue
                if dist[h1][w1] > dist[h][w] + 1:
                    dist[h1][w1] = dist[h][w] + 1
                    q.append((h1, w1))
        return dist[gh][gw]

    ans = 0
    for sh in range(H):
        for sw in range(W):
            for gh in range(H):
                for gw in range(W):
                    if gw==sw and gh==sh:
                        continue
                    if l[gh][gw] or l[sh][sw]:
                        continue
                    ans = max(ans, dfs(sh, sw, gh, gw))
    print(ans)

solve()