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 None:
                dist[w][x] = d + 1
                que.append((w, x))
    mi = s
    mj = t
    d = 0
    for i in range(H):
        for j in range(W):
            if dist[i][j] is not None:
                if dist[i][j] > d:
                    d = dist[i][j]
                    mi = i
                    mj = j
    return (d, (mi, mj))

for i in range(H):
    j = S[i].find(".")
    if j >= 0:
        _, (u, v) = bfs(i, j)
        d, _ = bfs(u, v)
        print(d)
        break