#include <bits/stdc++.h>
using namespace std;
int main() {
  int v[1001], i, k = 0, n;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> v[i];
  for (i = 2; i <= n - 1; i++) {
    if (((v[i] > v[i - 1]) && (v[i] > v[i + 1])) ||
        ((v[i] < v[i - 1]) && (v[i] < v[i + 1])))
      k++;
  }
  cout << k;
}
