#include <bits/stdc++.h>
using namespace std;
int arr[1000];
int main() {
  int n;
  scanf("%d", &n) == 0;
  for (decltype(0) i = 0; i < n; i++) scanf("%d", &arr[i]) == 0;
  int res = 0;
  for (decltype(1) i = 1; i < n - 1; i++) {
    if (arr[i] > arr[i + 1] && arr[i] > arr[i - 1]) {
      res++;
    }
    if (arr[i] < arr[i + 1] && arr[i] < arr[i - 1]) {
      res++;
    }
  }
  printf("%d", res);
}
