import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main=do
    n<-readLn::IO Int
    as<-unfoldr(B.readInt.B.dropWhile(==' '))<$>B.getLine
    print $ sol 0 as
sol n [] = n+1
sol n [x] = n+1
sol n (a:b:as)
    | a == b = sol n (b:as)
    | a < b  = solf n (<) (b:as)
    | otherwise = solf n (>) (b:as)
solf n _ [] = n+1
solf n _ [x] = n+1
solf n f (a:b:as)
    | a == b = solf n f (b:as)
    | f a b  = solf n f (b:as)
    | otherwise = sol (n+1) (b:as)
