#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[1005], i, sum;
  while (cin >> n) {
    sum = 0;
    for (i = 0; i < n; ++i) {
      cin >> a[i];
    }
    for (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;
}
