import numpy as np
h, w = list(map(int, input().split()))
ss = []
for _ in range(h):
    s = input()
    s = s.replace(".", "0").replace("#", "1")
    s = list(map(int, list(s)))
    ss.append(s)
ss = np.array(ss)
    

from collections import deque
def find(now_h, now_w):
    dp = np.zeros([h, w], dtype = np.int32) + 9999
    dp[now_h, now_w] = 0
    que = deque()
    que.append((now_h, now_w))
    while len(que) > 0:
        now_h, now_w = que.pop()
        for mh, mw in ([0,1], [0,-1], [1,0], [-1,0]):
            next_h = now_h + mh
            next_w = now_w + mw
            if next_h < 0 or next_h >= h or next_w < 0 or next_w >= w:
                continue
            if ss[next_h, next_w] == 1:
                continue
            if dp[next_h, next_w] > dp[now_h, now_w] + 1:
                dp[next_h, next_w] = dp[now_h, now_w] + 1
                que.append((next_h, next_w))
    return dp

maximum = 0
for sh in range(h):
    for sw in range(w):
        if ss[sh, sw] == 0:
            dp = find(sh, sw)
            score = np.max(dp[dp != 9999])
            if maximum < score:
                maximum = score

print(maximum)