from collections import deque


def find_farthest(adj, start):
    distance = [float("inf")] * len(adj)
    q = deque([(start, 0)])
    while len(q):
        cur, d = q.popleft()
        if distance[cur] <= d:
            continue
        distance[cur] = d
        for nxt in adj[cur]:
            if distance[nxt] > d+1:
                q.append((nxt, d+1))
    ret = (-1, -1)
    for i, d in enumerate(distance):
        if d != float("inf") and d > ret[1]:
            ret = (i, d)
    return ret


def main():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    adj = [set() for _ in range(H*W)]
    start = None
    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                continue
            if i >= 1 and S[i-1][j] == ".":
                adj[i*W+j].add((i-1)*W+j)
                adj[(i-1)*W+j].add(i*W+j)
            if j >= 1 and S[i][j-1] == ".":
                adj[i*W+j].add(i*W+(j-1))
                adj[i*W+(j-1)].add(i*W+j)
            start = i*W+j
    nstart, _ = find_farthest(adj, start)
    nstart, _ = find_farthest(adj, nstart)
    _, ans = find_farthest(adj, nstart)
    print(ans)


if __name__ == "__main__":
    main()
