n = gets.to_i a = gets.split(" ").map(&:to_i) tmp = a.index(1) last = n (1..n).each{|x| index = a.index(x) if index < tmp then last = x - 1 break end tmp = index } puts n - last