'use strict';

function main(stdin) {
  const input = stdin.split('\n')//.map(v => parseInt(v, 10));
  const N = Number(input[0]);
  const p = input[1].split(' ').map(v => parseInt(v, 10));

  let cnt = 0;

  for (let i = 1; i < N - 1; ++i) {
    const ary = [p[i - 1], p[i], p[i + 1]];
    if (p[i] === ary.sort((a, b) => a - b)[1]) ++cnt;
  }
  
  console.log(cnt);
}

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