import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
  std.functional, std.container, std.typecons;

void main() {
  int n = readln.chomp.to!int;
  int[] p = readln.split.to!(int[]);

  int ans = 0;
  foreach(i; 1..(n-1)) {
    auto sorted = [p[i-1], p[i], p[i+1]].sort();
    if(sorted[1] == p[i]) ans++;
  }
  ans.writeln;
}
