H, W = map(int, input().split())

S = [list(input()) for _ in range(H)]

check = [[False]*W for _ in range(H)]

res = 0


for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        if check[i][j]:
            continue

        mc = [[-1]*W for _ in range(H)]
        mc[i][j] = 0

        q = [(i, j)]
        while q:
            y, x = q.pop(0)
            for a, b in [(-1,0), (0,-1), (0,1), (1,0)]:
                if y+a < 0 or y+a >= H or x+b < 0 or x+b >= W:
                    continue

                if S[y+a][x+b] == "#":
                    continue


                if mc[y+a][x+b] == -1 or mc[y+a][x+b] > mc[y][x]+1:
                    mc[y+a][x+b] = mc[y][x]+1

                    res = max(res, mc[y+a][x+b])
                    q.append([y+a, x+b])

                    check[y][x] = True



print(res)