from collections import deque

H, W = map(int, input().split())
S = [input() for _ in range(H)]
def bfs(s, t):
    dist = [[None] * W for _ in range(H)]
    que = deque([(s, t)])
    dist[s][t] = 0
    while que:
        u, v = que.popleft()
        d = dist[u][v]
        G = []
        if u > 0 and S[u-1][v] == ".":
            G.append((u-1, v))
        if u < H - 1 and S[u+1][v] == ".":
            G.append((u+1, v))
        if v > 0 and S[u][v-1] == ".":
            G.append((u, v-1))
        if v < W - 1 and S[u][v+1] == ".":
            G.append((u, v+1))
        for w, x in G:
            if dist[w][x] is not None:
                continue
            dist[w][x] = d + 1
            que.append((w, x))
    return max(max((d, (i, j)) for j, d in enumerate(di) if d is not None) for i, di in enumerate(dist))

for i in range(H):
    j = S[i].find(".")
    if j >= 0:
        break


_, (u, v) = bfs(i, j)
d, _ = bfs(u, v)
print(d)