N = gets.to_i
arr = N.times.map{ gets.to_i }
stack = []
counter = 0
arr.each do |i|
  if !stack.empty? && stack.last >= i
    if stack[stack.count - 2] < stack[stack.count - 1]
      flag = false
      while !stack.empty?
        if stack[stack.count - 2] < stack[stack.count - 1]
          flag = true
          stack.pop
        else
          break
        end
      end
      stack.pop
      counter += 1 if flag
    end
  end
  stack.push(i)
end

while !stack.empty?
  i = stack.count
  if stack[i - 2] < stack[i - 1]
    flag = false
    while !stack.empty?
      if stack.count >= 2 && stack[i - 2] < stack[i - 1]
        flag = true
        stack.pop
      else
        break
      end
    end
    stack.pop
    counter += 1 if flag
  else
    stack.pop
    counter += 1
  end
end

puts counter