import Control.Applicative
import Control.Arrow

main = do
  n <- getLine
  as <- map read . words <$> getLine :: IO [Int]

  print $ length $ solve as

  where
    solve [] = []
    solve xs = if length a >= length d then a : solve as else d : solve ds
      where
        (a,as) = aux xs 1
        (d,ds) = aux xs (-1)

    aux (x:[]) _ = ([x],[])
    aux (x:y:xs) 1 = if x<=y then first (x:) (aux (y:xs) 1) else ([x], y:xs)
    aux (x:y:xs) (-1) = if x>=y then first (x:) (aux (y:xs) (-1)) else ([x], y:xs)
