import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

toInts :: IO [Int]
toInts = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

solver :: [Int] -> Int
solver [] = 0
solver (x:[]) = 0
solver (x:y:[]) = 0
solver (x:y:z:rest) =
  (if (x < y && y < z) || (x > y && y > z)
     then 1
     else 0) +
  solver (y : z : rest)

main :: IO ()
main = do
  _ <- getLine
  dat <- toInts
  print $ solver dat
