import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace

main :: IO ()
main = do
  n <- readLn :: IO Int
  ps <- map read.words <$> getLine :: IO [Int]
  list <- forM [1..n-2] $ \i -> if ps !! i == (sort [(ps !! (i-1)),(ps !! i) ,(ps !! (i+1))]) !! 1
    then return (1 :: Int)
    else return (0 :: Int)

  putStrLn $ show $ sum (list :: [Int])
