#include <bits/stdc++.h>
const int Max = 1010;
int a[Max];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 1; i < n - 1; i++) {
      if (a[i] > a[i - 1] && a[i] > a[i + 1]) {
        sum++;
      }
      if (a[i] < a[i - 1] && a[i] < a[i + 1]) {
        sum++;
      }
    }
    printf("%d\n", sum);
  }
}
