import Control.Applicative ((<$>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  getLine
  solve <$> getl (map read . words) >>= print

solve :: [Int] -> Int
solve = f 0
  where
    f c (x:y:z:zs) | ((y > x && y > z) || (y < x && y < z)) && x /= z = f (c + 1) (y:z:zs)
                   | otherwise = f c (y:z:zs)
    f c _ = c

getl :: (String -> a) -> IO a
getl f = f <$> getLine