#include <bits/stdc++.h>
using namespace std;
double chisl, znam;
int n, arr[1007];
long long counter;
set<double> completed;
pair<double, double> elem[100];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  n--;
  for (int i = 1; i < n; i++) {
    if (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]) {
      counter++;
    }
    if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) {
      counter++;
    }
  }
  cout << counter;
}
