#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long a, z = 0;
  cin >> a;
  long long ar[a];
  for (long long i = 0; i < a; i++) {
    cin >> ar[i];
  }
  for (long long i = 0; i < a; i++) {
    if ((ar[i] < ar[i - 1] && ar[i] < ar[i + 1] ||
         ar[i] > ar[i - 1] && ar[i] > ar[i + 1]) &&
        i != 0 && i != a - 1) {
      z++;
    }
  }
  cout << z << endl;
  return 0;
}
