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

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

main = do
    n <- getInt
    ps <- getIntList
    print . sum $ zipWith3 check ps (drop 1 ps) (drop 2 ps)

check x y z | x < y && y < z = 1
            | z < y && y < x = 1
            | otherwise = 0