from collections import deque
from itertools import combinations

H,W=list(map(int,input().split()))
S=[input() for _ in range(H)]
pts=[[j,i] for i in range(W) for j in range(H)]
d=[[-1,0],[1,0],[0,1],[0,-1]]
ret=0

for s,g in combinations(pts,2):
    if S[s[0]][s[1]]=='#' or S[g[0]][g[1]]=='#':
        continue

    q=deque([s+[0]])
    while len(q)>0:
        h,w,cnt=q.popleft()

        if g[0]==h and g[1]==w:
            ret=max(ret,cnt)
            break

        for dw,dh in d:
            if 0<=w+dw<W and 0<=h+dh<H and S[h+dh][w+dw]=='.':
                q.append([h+dh,w+dw,cnt+1])

print(ret)