# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
end

nums = inputs[1]

def rec(arr, buf)
  l = arr.size
  return buf if l == 0
  l.times do |j|
    if arr[l-1-j] == l-j
      arr.delete_at(l-1-j)
      return rec(arr, (buf << (l-j)))
    end
  end
  return [-1]
end

puts rec(nums, []).reverse
