H,W = map(int,input().split())
A = []

for i in range(H):
    t = list(input())
    A.append(t)

tate = (-1,1,0,0)
yoko = (0,0,-1,1)
answer = 0

def move(i,j):
    for p, q in zip(tate, yoko):
        m = i + p
        n = j + q
        if m >= 0 and m < H:
            if n >= 0 and n < W:
                if A[m][n] == '.':
                    if dp[m][n] > dp[i][j]:
                        dp[m][n] = dp[i][j] + 1
                        move(m,n)

for i in range(H):
    for j in range(W):
        dp = [[10**4 for i in range(W)] for j in range(H)]
        if A[i][j] == '.':
            dp[i][j] = 0
            move(i,j)
            for k in range(H):
                for l in range(W):
                    if dp[k][l] < 10**4:
                        answer = max(answer,dp[k][l])

print(answer)