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 i += 1 while (numary[i][1] > numary[i+1][1]) puts n - (i+1)