import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto p = readln.chomp.split.to!(int[]);
  int cnt;
  foreach (i; 1..p.length-1) {
    if (p[i-1] < p[i] && p[i] < p[i+1]
    ||  p[i-1] > p[i] && p[i] > p[i+1]) {
      cnt++;
    }
  }

  cnt.writeln;
}
