n = gets.to_i
nums = gets.split.map(&:to_i)
count = 0

flag = false
while !flag do
  before = nums.dup
  d_count = 0
  l = nums.length
  nums.delete_if.with_index do |num, i|
    #puts num
    #puts i
    if num > ((i + 1 - d_count) || num == nums[i-1-d_count]) && i != l-1
      d_count += 1
      count += 1
      true
    elsif i == l-1 && num > (i + 1 - d_count)
      d_count += 1
      count += 1
      true
    else
      false
    end
  end
  if nums == before
    flag = true
  end
  #print nums
end
#print nums

if nums.size == 0
  puts -1
else
  puts n - nums.uniq.length
end