import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Ord

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    as <- getIntList
    print . g $ f as

f [] = []
f (a:[]) = EQ : []
f (a:b:as)= (compare a b) : f (b:as)

g [] = 0
g as | null gs || null ls = 1
     | length lts > length gts = 1 + g (tail gs)
     | otherwise = 1 + g (tail ls)
    where (lts, gs) = span (/= GT) as
          (gts, ls) = span (/= LT) as