def main():
    import sys
    from collections import deque
    input = sys.stdin.readline

    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        line = input().rstrip('\n')
        grid.append(line)

    d = [(0, 1), (0, -1), (1, 0), (-1, 0)]
    ans = 0
    for i in range(H):
        for j in range(W):
            ans_new = 0
            seen = [[-100] * W for _ in range(H)]
            seen[i][j] = 0
            que = deque()
            que.append(i*W+j)
            while que:
                v = que.popleft()
                y, x = divmod(v, W)
                for dx, dy in d:
                    x_new = x+dx
                    y_new = y+dy
                    if 0 <= y_new < H and 0 <= x_new < W:
                        if seen[y_new][x_new] == -100:
                            if grid[y_new][x_new] == '.':
                                que.append(y_new * W + x_new)
                                seen[y_new][x_new] = seen[y][x] + 1
                                if ans_new < seen[y_new][x_new]:
                                    ans_new = seen[y_new][x_new]
            ans = max(ans, ans_new)

    print(ans)


if __name__ == '__main__':
    main()
