def restore_segment_tree(n, nums):
    if n != 2**int(math.log2(n) + 0.5) - 1 or nums[0] != min(nums):
        return -1

    arr = [float('inf')] * n
    index = 0
    root = nums[index]
    arr[index] = root

    def fill_tree(arr, index):
        left_child = 2 * index + 1
        right_child = 2 * index + 2

        if left_child < n and arr[left_child] == float('inf'):
            arr[left_child] = min(arr[index], arr[right_child])
            fill_tree(arr, left_child)

        if right_child < n and arr[right_child] == float('inf'):
            arr[right_child] = min(arr[index], arr[left_child])
            fill_tree(arr, right_child)

    fill_tree(arr, index)
    return arr


# Пример использования
n = int(input())
nums = list(map(int, input().split()))

result = restore_segment_tree(n, nums)
if result == -1:
    print(-1)
else:
    print(*result)