from collections import defaultdict
H, W = map(int, input().split())
M = []
for h in range(H):
    M.append(input()+'#')
M.append('#'*(W+1))

INF = 10000
def default():
    return INF
N = []
d = defaultdict(default)
for h in range(H):
    for w in range(W):
        hw = (h, w)
        d[(hw, hw)] = 0
        if M[h][w] == '#':
            continue
        N.append(hw)
        if M[h+1][w] == '.':
            n = (h+1, w)
            d[(hw, n)] = d[(n,hw)] = 1
        if M[h][w+1] == '.':
            n = (h, w+1)
            d[(hw, n)] = d[(n,hw)] = 1

for i in N:
    for j in N:
        for k in N:
            alt = d[(i,k)] + d[(k,j)]
            if d[(i,j)] > alt:
                d[(i,j)] = alt
                d[(j,i)] = alt
for h in range(H):
    for w in range(W):
        #print(d[(0, 0), (h, w)])
        pass
    #print()
#print(d[(H-1,W-1), (H-2,W-1)])
#print(d[(H-2,W-1), (H-1,W-1)])
print(max(x for x in d.values() if x != INF))

