N = gets.to_i a = gets.split.map(&:to_i) orderCount = 1 # 大きい方から順番に並んでいる個数を数える m = a.length (2..m).reverse_each do |i| if a.index(i-1) > a.index(i) break else orderCount += 1 end end puts m - orderCount