let n = Int(readLine()!)!
let p = readLine()!.characters.split(" ").map{Int(String($0))!}
var ans = 0
for i in 1..<n-1 {
    let arr = [p[i-1], p[i], p[i+1]].sort()
    if p[i] == arr[1] {
        ans += 1
    }
}
print(ans)
