import Control.Arrow (second)

import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )
import Data.List

readInt :: IO Int
readInt = fst . fromJust . C.readInt <$> C.getLine

readInt' :: C.ByteString -> Maybe (Int, C.ByteString)
readInt' = fmap (second C.tail) . C.readInt

main = do
  n  <- readInt
  as <- VU.unfoldrN n readInt' <$> C.getLine
  print . f $ VU.toList as

f :: [Int] -> Int
f = h 0 

h :: Int -> [Int] -> Int
h s []  = s+1
h s [_] = s+1
h s (i:is@(j:_))
  | i == j    = h s is
  | i <  j    = g s (<) is
  | otherwise = g s (>) is

g :: Int -> (Int -> Int -> Bool) -> [Int] -> Int
g s _ []  = s+1
g s _ [_] = s+1
g s op (i:is@(j:_))
  | i == j    = g s op is
  | i `op` j  = g s op is
  | otherwise = h (s+1) is