INFTY = 1000
H,W = map(int,input().split())
S = [input().strip() for _ in range(H)]
G = {(i,j):[] for i in range(H) for j in range(W)}
for i in range(H):
    for j in range(W):
        if j+1<W and S[i][j+1]==".":
            G[(i,j)].append((i,j+1))
        if j-1>-1 and S[i][j-1]==".":
            G[(i,j)].append((i,j-1))
        if i+1<H and S[i+1][j]==".":
            G[(i,j)].append((i+1,j))
        if i-1>-1 and S[i-1][j]==".":
            G[(i,j)].append((i-1,j))
d = {(i,j):{(k,l):INFTY for k in range(H) for l in range(W)} for i in range(H) for j in range(W)}
for i in range(H):
    for j in range(W):
        for x in G[(i,j)]:
            k,l = x[0],x[1]
            d[(i,j)][(k,l)] = 1
for i in range(H):
    for j in range(W):
        for k in range(H):
            for l in range(W):
                for m in range(H):
                    for n in range(W):
                        d[(k,l)][(m,n)]=min(d[(k,l)][(m,n)],d[(k,l)][(i,j)]+d[(i,j)][(m,n)])
cmax = 0
for i in range(H):
    for j in range(W):
        for k in range(H):
            for l in range(W):
                if d[(i,j)][(k,l)]<INFTY:
                    cmax = max(cmax,d[(i,j)][(k,l)])
print(cmax)