#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int mod = 1000000007;
  int n;
  cin >> n;
  vector<int> vals(n);
  for (int i = 0; i < n; ++i) {
    cin >> vals[i];
  }
  int rez = 0;
  for (int i = 1; i < n - 1; ++i) {
    if (vals[i] < vals[i + 1] && vals[i] < vals[i - 1] ||
        vals[i] > vals[i + 1] && vals[i] > vals[i - 1]) {
      ++rez;
    }
  }
  cout << rez;
  return 0;
}
