open System 

let R() = Console.ReadLine()

let f : int array -> int =
    Array.windowed 3
    >> Array.where (fun xs -> 
        xs.[0] < xs.[1] && xs.[1] < xs.[2] 
       || xs.[2] < xs.[1] && xs.[1] < xs.[0])
    >> Array.length

let n = int <| R()
let p = R().Split() |> Array.map (string>>int)

f p 
|> printfn "%i"