H,W = map(int, input().split())

S = ["" for _ in range(H)]
for i in range(H):
    S[i] = input()

INF = float("inf")
dp = [[INF for _ in range(H*W)] for _ in range(H*W)]

for i in range(H):
    for j in range(W):
        
        if j != W-1 and S[i][j] == "." and S[i][j+1] == ".":
            dp[(H*i)+j][(H*i)+j+1] = 1
            dp[(H*i)+j+1][(H*i)+j] = 1

        if i != H-1 and S[i][j] == "." and S[i+1][j] == ".":
            dp[(H*i)+j][(H*(i+1))+j] = 1
            dp[(H*(i+1))+j][(H*i)+j] = 1
    
        dp[(H*i)+j][(H*i)+j] = 0


N = H*W
for k in range(N):
    for i in range(N):
        for j in range(N):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

ans = 0
for i in range(N):
    for j in range(N):
        if dp[i][j] != INF:
            ans = max(ans, dp[i][j])
 
print(ans)
