import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- map (read :: String -> Int) . words <$> getLine
  print $ solve as

solve :: [Int] -> Int
solve as = go as' (if length as' /= 1
                   then (head y <= head (head ys))
                   else True)
  where
    as'@(y:ys) = group as
    go :: [[Int]] -> Bool -> Int
    go [] _ = 0
    go [x] _ = 1
    go (x:xs@(z:zs)) b
      | head x <= head z , b = go xs b 
      | head x >= head z , not b = go xs b
      | otherwise = if (not.null) zs
                    then 1 + go zs (head z <= head (head zs))
                    else 1 + go xs b
