let n = Int(readLine()!)!
let p = readLine()!.characters.split(" ").map{Int(String($0))!}
print((1..<n-1).reduce(0){i,j in let k=(p[j-1]<p[j]&&p[j]<p[j+1])||(p[j-1]>p[j]&&p[j]>p[j+1]) ?1:0;return i+k})