'use strict'

const main = (INPUT) => {
  const input = INPUT.split('\n')
  const n = Number(input[0])
  const p = input[1].split(' ').map(n => Number(n))
  let ans = 0
  for (let i = 1; i < p.length - 1; i++) {
    if (p[i - 1] <= p[i] && p[i] <= p[i + 1] || p[i - 1] >= p[i] && p[i] >= p[i + 1]) {
      ans++
    }
  }
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))
