N = gets.to_i A = gets.split.map(&:to_i) B = A.sort.reverse P = Hash.new { |h, k| h[k] = [] } d = 0 ans = 0 A.each_with_index do |a, i| P[a] << i end B.each_with_index do |b, i| idx = (P[b].pop - d) % (N - i + 1) col = N - i - 1 next if idx == col d += idx + 1 ans += 1 end puts ans