N = gets.to_i A = gets.split.map(&:to_i) pos = Hash.new A.each_with_index do |a, i| pos[a] = i end checked = Hash.new(false) ans = 0 A.sort.each do |a| idx = pos[a] next if checked[idx] checked[idx] = true checked[idx - 1] = true ans += 1 end puts ans