#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& it : a) {
    cin >> it;
  }
  int count = 0;
  for (int i = 1; i < a.size() - 1; i++) {
    if ((a[i] > a[i - 1] && a[i] > a[i + 1]) ||
        (a[i] < a[i - 1] && a[i] < a[i + 1])) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
