let n=Int(readLine()!)!
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}
let pp=readInts()
var count=0
for i in 1...(n-1){
  if (pp[i-1]<pp[i])&&(pp[i]<pp[i+1]){
    count+=1
  }else if (pp[i-1]>pp[i])&&(pp[i]>pp[i+1]){
    count+=1
  }
}

print(count)


