#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, sum = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  if (n <= 2) {
    cout << 0 << endl;
  } else {
    for (int i = 1; i < n - 1; i++) {
      if (a[i] > a[i - 1] && a[i] > a[i + 1])
        sum++;
      else if (a[i] < a[i - 1] && a[i] < a[i + 1])
        sum++;
    }
    cout << sum << endl;
  }
  return 0;
}
