import heapq

def construct_segment_tree(a):
    if not a:
        return []

    heapq.heapify(a)
    while len(a) % 2 != 0:
        a.append(float('inf'))

    root = [(a[i], a[i + 1]) for i in range(0, len(a), 2)]
    current_level = root
    next_level = []

    while current_level:
        node = heapq.heappop(current_level)
        left_child = (node[0], node[1]) if node[0] != float('inf') else None
        right_child = (node[1], node[1]) if node[1] != float('inf') else None

        if left_child and right_child:
            next_level.append(left_child)
            next_level.append(right_child)

        elif left_child:
            next_level.append(left_child)

        elif right_child:
            next_level.append(right_child)

        current_level = next_level
        next_level = []

    return root

def check_solution(n, a):
    root = construct_segment_tree(a)
    return n == len(root)

def restore_array(p, a):
    n = len(a)
    if not check_solution(p, a):
        return -1

    result = []
    stack = [(a[i], a[i + 1]) for i in range(0, len(a), 2)]

    while stack:
        node = stack.pop()
        if node[0] != float('inf'):
            result.append(node[0])
        if node[1] != float('inf'):
            result.append(node[1])

    return result

def solve(case):
    p, n = map(int, input().split())
    a = list(map(int, input().split()))

    result = restore_array(p, a)
