#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,c=0;cin>>n;
  vector<int> p(n);
  for(int i=0; i<n; i++)cin>>p[i];
  for(int i=1; i<n-1; i++){
    if(p[i]==p[i-1]+p[i]+p[i+1]-(max({p[i-1],p[i],p[i+1]})+min({p[i-1],p[i],p[i+1]})))c++;
  }
  cout<<c<<endl;
}