#include <bits/stdc++.h>
using namespace std;
int a[1000000];
int main() {
  int m, n;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) scanf("%d", &a[i]);
  int ans = 0;
  for (int i = 1; i < m - 1; i++) {
    if (a[i] > a[i - 1] && a[i] > a[i + 1] ||
        a[i] < a[i - 1] && a[i] < a[i + 1])
      ans++;
  }
  printf("%d\n", ans);
}
