#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int s[n],i,count=0;
  for(i=0;i<n;i++){
    cin >> s[i];
  }
  for(i=0;i<n-2;i++){
    if((s[i]<s[i+1] && s[i+1]<s[i+2]) || (s[i]>s[i+1] && s[i+2]<s[i+1])){
      count++;
    }
  }
  cout << count;
}