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