process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line)
});
 
reader.on('close', () => {
 
  var n = lines[1].split(' ')
  for (var k in n) n[k] = parseInt(n[k])
 
  var r = 0
 
  for (var i = 1; i < n.length - 1; i++) {
    var ary = [
      n[i - 1],
      n[i],
      n[i + 1]
    ].sort()
    if (ary[1] === n[i]) r++
  }
 
  console.log(r)
 
});