# 再々修正。三度目の正直! n = gets.to_i num = gets.split.map(&:to_i) numary = [] num.each_with_index {|num, idx| numary << [num, idx] } numary.sort!.reverse! i = 0 while i < n-1 break if numary[i][1] < numary[i+1][1] i += 1 end puts n - (i+1)