func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

let n:Int=Int(readLine()!)!
let per=readInts()
var ans=0;
for i in 0..<n-2{
  if((per[i]<per[i+1]&&per[i+1]<per[i+2])||(per[i]>per[i+1]&&per[i+1]>per[i+2])){ans+=1}
}

print(ans)