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