H, W = list(map(int, input().split()))
S = ["#"*(W+1)] + ["#"+input()+"#" for _ in range(H)] + ["#"*(W+1)]
adj = [[[[float("inf")] * W for _ in range(H)] for _ in range(W)] for _ in range(H)]
for h in range(H):
    for w in range(W):
        if S[h+1][w+1] != ".":
            continue
        adj[h][w][h][w] = 0
        for dh, dw in zip((0, 1, 0, -1), (1, 0, -1, 0)):
            if S[h+dh+1][w+dw+1] == ".":
                adj[h][w][h+dh][w+dw] = 1

from itertools import product
for (h1, h2, h3), (w1, w2, w3) in product(product(range(H), repeat=3), product(range(W), repeat=3)):
    adj[h1][w1][h3][w3] = min(adj[h1][w1][h3][w3], adj[h1][w1][h2][w2]+adj[h2][w2][h3][w3])

print(max(filter(lambda x: x != float('inf'), (adj[h1][w1][h2][w2] for (h1, w1), (h2, w2) in product(product(range(H), range(W)), repeat=2)))))