let hoge (x : int list) =
    let a = List.sort x
    x.[1] = a.[1]

let n = int (stdin.ReadLine())
let p = stdin.ReadLine().Split() |> Array.map int
let mutable c = 0
[for i in 1..n - 2 -> [p.[i - 1]; p.[i]; p.[i + 1]]] |> List.iter (fun d -> if (hoge d = true) then c <- c + 1)
printfn "%d" c