from scipy.sparse.csgraph import floyd_warshall


def main():
    H, W = map(int, input().split())
    S = []

    def get_index(h, w):
        return h * W + w

    for _ in range(H):
        S.append(input())

    l = [[0 for _ in range(H * W)] for _ in range(H * W)]
    for h in range(H):
        for w in range(W):
            if 0 <= h - 1 and S[h - 1][w] == ".":
                l[get_index(h, w)][get_index(h - 1, w)] = 1
            if h + 1 < H and S[h + 1][w] == ".":
                l[get_index(h, w)][get_index(h + 1, w)] = 1
            if 0 <= w - 1 and S[h][w - 1] == ".":
                l[get_index(h, w)][get_index(h, w - 1)] = 1
            if w + 1 < W and S[h][w + 1] == ".":
                l[get_index(h, w)][get_index(h, w + 1)] = 1

    fw = floyd_warshall(l)
    #print(fw[0][2])
    ans = 0
    for i in range(H * W):
        for j in range(H * W):
            ans = max(ans, fw[i][j] if not fw[i][j] == float("inf") else 0)

    print(int(ans))


main()
