n = gets.to_i a_list = gets.split.map(&:to_i) a_list.reverse_each do |a| n -= 1 if a == n end puts n