N = gets.to_i
asx = gets.strip.split.map(&:to_i)
ary = asx
kir = []
unless ary.include?(1) then
  kir[0] = -1
else
  i = 1
  while i > 0 do
    if ary.include?(i) then
      kir[i-1] = ary.find_index(i) #これがiに到達するまでに割る枚数
      ary.slice!(0..kir[i-1])
      i += 1
    else
      kir.push(ary.size)
      break
    end
  end
end
puts kir.sum