import Foundation
 
let input_line = readLine()!
 
let split = input_line.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
let N = Int(input_line)!
 
var Pi = [Int]()
let input_line2 = readLine()!

let splits = input_line2.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
Pi = splits.map {Int($0)!}

var counter = 0

for i in 0..<N - 2 {
    if Pi[i] < Pi[i + 1] && Pi[i + 1] < Pi[i + 2] {
        counter += 1
    } else if Pi[i + 2] < Pi[i + 1] && Pi[i + 1] < Pi[i] {
        counter += 1
    }
}
print(counter)