H,W=map(int,input().split())
S=[[] for _ in range(H)]

for i in range(H):
    S[i]=input()
    
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

n=H*W
inf=10**9

d = [[inf]*n for _ in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(H):
    for j in range(W):
        if S[i][j]==".":
            if j+1<W:
                if S[i][j+1]==".":
                    d[i*H+j][i*H+j+1]=1
                    d[i*H+j+1][i*H+j]=1
            if i+1<H:
                if S[i+1][j]==".":
                    d[i*H+j][(i+1)*H+j]=1
                    d[(i+1)*H+j][i*H+j]=1
    
        
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
ans=0

warshall_floyd(d)

for i in range(n):
    for j in range(n):
        if d[i][j]>=ans and d[i][j]<=inf-10:
            ans=d[i][j]

print(ans)