#include <bits/stdc++.h>
using namespace std;
int main() {
  int sz, count = 0;
  cin >> sz;
  vector<long long> a;
  for (int i = 0; i < sz; i++) {
    long long x;
    cin >> x;
    a.push_back(x);
  }
  for (int i = 1; i < sz - 1; i++) {
    if (a[i] > a[i - 1] && a[i] > a[i + 1]) ++count;
    if (a[i] < a[i - 1] && a[i] < a[i + 1]) ++count;
  }
  cout << count << endl;
}
