let a=Int(readLine()!)!
let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

var i = 0
var count = 0

for i in 1..<a - 1 {
  if( ( arr[ i - 1 ] < arr[i] ) && ( arr[i] < arr[ i + 1 ] ) ) {
    count += 1
  } else if ( ( arr[ i - 1 ] > arr[i] ) && ( arr[i] > arr[ i + 1 ] ) ) {
    count += 1
  }
}

print( count )