from collections import deque
from itertools import product

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

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

    ans = 0

    for sh,sw,gh,gw in product(range(H),range(W),range(H),range(W)):
        if gw==sw and gh==sh:
            continue
        if l[gh][gw] or l[sh][sw]:
            continue

        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))
        ans = max(ans, dist[gh][gw])
        
    print(ans)

solve()