#include <bits/stdc++.h>
using namespace std;
int n, numbers[1000];
int main() {
  cin >> n;
  if (n < 3) {
    cout << "0";
    return 0;
  }
  for (int i = 0; i < n; ++i) cin >> numbers[i];
  int result = 0;
  for (int i = 1; i < n - 1; ++i)
    if ((numbers[i - 1] > numbers[i] && numbers[i + 1] > numbers[i]) ||
        numbers[i - 1] < numbers[i] && numbers[i + 1] < numbers[i])
      ++result;
  cout << result;
}
