n = gets.to_i a_list = gets.chomp.split.map(&:to_i) still_max = n count = 0 a_list.reverse_each do |v| if v == still_max still_max -= 1 else count += 1 end end puts count