from itertools import product

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

V = list(product(range(H), range(W)))

INF = len(V)
dp = dict(product(product(V, V), [INF]))

for v in V:
    dp[v, v] = 0

for v in V:
    x, y = v
    if S[x][y] == '.':
        for dx, dy in [(0, 1), (1, 0), (0, -1), (-1, 0)]:
            xn = x + dx
            yn = y + dy
            if 0 <= xn < H and 0 <= yn < W and S[xn][yn] == '.':
                vn = (xn, yn)
                dp[v, vn] = 1

for k in V:
    for i in V:
        for j in V:
            if dp[i, j] > dp[i, k] + dp[k, j]:
                dp[i, j] = dp[i, k] + dp[k, j]

result = 0
for v in V:
    for w in V:
        if dp[v, w] != INF:
            result = max(result, dp[v, w])

print(result)