{- SPDX-License-Identifier: X11
 -
 - Copyright 2020 Elias Yuan <a@jthv.ai>, MIT/X11 License
 -   https://jthv.ai/LICENSE/X11.txt
 -
 - ANU-CPC Observation Workshop - B: Sorted Arrays
 -   2020-05-06
 -}

module Main where

import System.IO (print)

solve :: String -> Int
solve = sol . unDup . strToInts
  where
    strToInts :: String -> [Int]
    strToInts = map (read :: String -> Int) . words

    unDup :: [Int] -> [Int]
    unDup (x:y:ys)
      | x == y    = unDup (y:ys)
      | otherwise = x:unDup (y:ys)
    unDup x = x

    sol :: [Int] -> Int
    sol []  = 0
    sol [_] = 1
    sol (x:y:ys)
      | x < y     = s 1 True (y:ys)
      | x > y     = s 1 False (y:ys)
      | otherwise = error "sol: That shouldn't have been possible"
      where
        s :: Int -> Bool -> [Int] -> Int
        s acc fl (a:b:c:cs)
          | fl && a < b || not fl && a > b = s acc fl (b:c:cs)
          | fl && a > b || not fl && a < b = s (acc + 1) (b < c) (b:c:cs)
          | otherwise                      = error "s: That shouldn't have been possible"

        s acc fl [a,b]
          | fl && a < b || not fl && a > b = acc
          | fl && a > b || not fl && a < b = acc + 1
          | otherwise                      = error "s: That shouldn't have been possible"

        s acc _ _ = acc


main :: IO ()
main = getLine >> getLine >>= \x -> print $ solve x
