let n=Int(readLine()!)!
let pp=readLine()!.split(separator:" ")
var count=0
for i in 1...(n-1){
  if ((pp[i-1]>pp[i])&&(pp[i]>pp[i+1]))||((pp[i-1]<pp[i])&&(pp[i]<pp[i+1])){
    count+=1
  }
}
print(count)
