import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto n = readNum!int;
  auto p = readNums!int;
  int ret;

  foreach(i; 1 .. n-1){
    auto s = p[i-1 .. i+2];

    if((s[0] < s[1] && s[1] <= s[2]) ||
       (s[0] >= s[1] && s[1] > s[2])){
      ret++;
    }
  }

  writeln(ret);
}
