H, W = [int(i) for i in input().split()]
S = [input() for _ in range(H)]
inf = 1000000
dist = [[inf]*(W*H) for _ in range(W*H)]

def bfs(s):
    seen = set()
    stk = [(s, 0)]
    while stk:
        pt, dst = stk.pop()
        ph, pw = pt//W, pt%W
        if(pt in seen):
            continue
        seen.add(pt)

        if(S[ph][pw]=='#'):
            dist[s][pt] = 0
            continue

        for x,y in ((1,0), (-1,0), (0, 1), (0,-1)):
            if((not 0<=pw+x<W )or (not 0<=ph+y<H)):
                continue
            else:
                ns = (ph+y)*W + (pw+x)
                stk.insert(0, (ns, dst+1))
        dist[s][pt] = min(dst, dist[s][pt])
        
ans = 0
for s in range(H*W-1):
    h, w = s//W, s%W
    if(S[h][w]=='#'):
        continue
    bfs(s)
    
    ans = max(ans, max(dist[s]))

print(ans)

