output_description: If there is no sequence of N operations after which a would be equal to b,
  print `-1`. If there is, print N lines. In the i-th line, the integer chosen
  in the i-th operation should be printed. If there are multiple solutions, any
  of them is accepted.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      b_1 \dots b_N
attempt: def checkJ(lst):
      good_jlist = []
      for i in range(len(lst)):
          if lst[len(lst) - i - 1] == len(lst) - i:
              good_jlist.append(len(lst) - i - 1)
      return good_jlist
  
  
  def subJ(lst, j):
      return lst[:j] + lst[j + 1 :]
  
  
  n = int(input())
  s = [int(i) for i in input().split()]
  stack_list = []
  stack_list.append([s, checkJ(s)])
  notfound = 0
  applylist = []
  while True:
      #     調べる番号がない場合
      if not stack_list[0][0]:
          notfound = 2
          break
      while not stack_list[0][1]:
          stack_list.pop(0)
          if not stack_list:
              notfound = 1
              break
          if not stack_list[0][0]:
              notfound = 2
              break
  
      #     調べるリストがない場合
      if notfound == 1 or notfound == 2:
          break
  
      currentStr = stack_list[0][0]
      applylist = applylist[: int(int(n) - len(currentStr))]
      currentCheckNum = stack_list[0][1].pop(0)
      if currentCheckNum == 0 and len(currentStr) > 1:
          continue
      nextStr = subJ(currentStr, currentCheckNum)
      if checkJ(s):
          stack_list.insert(0, [nextStr, checkJ(nextStr)])
      applylist.append(currentCheckNum + 1)
  #     print("current list")
  #     print(stack_list)
  if notfound == 1:
      print("-1")
  elif notfound == 2:
      for i in range(len(applylist)):
          print(applylist[int(n) - i - 1])
  
problem_description: Statement
  
  Snuke has an empty sequence a.
  
  He will perform N operations on this sequence.
  
  In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and
  insert j at position j in a (the beginning is position 1).
  
  You are given a sequence b of length N. Determine if it is possible that a is
  equal to b after N operations. If it is, show one possible sequence of
  operations that achieves it.
samples: [{"input": "3\n    1 2 1", "output": "1\n    1\n    2\n    \n\nIn this sequence of operations, the sequence a changes as follows:\n\n  * After the first operation: (1)\n  * After the second operation: (1,1)\n  * After the third operation: (1,2,1)\n\n* * *"}, {"input": "2\n    2 2", "output": "-1\n    \n\n2 cannot be inserted at the beginning of the sequence, so this is impossible.\n\n* * *"}, {"input": "9\n    1 1 1 2 2 1 2 3 2", "output": "1\n    2\n    2\n    3\n    1\n    2\n    2\n    1\n    1"}]