import qualified Data.ByteString.Char8 as BS
import Data.Maybe

main = do
  n <- readLn :: IO Int
  as <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine :: IO [Int]
  print $ solve as

solve :: [Int] -> Int


solve (a:b:c:as)
  | a < b && b < c = 1 + solve (b:c:as)
  | a > b && b > c = 1 + solve (b:c:as)
  | otherwise = solve (b:c:as)

solve a = 0