#include <bits/stdc++.h>
using namespace std;
int read() {
  char c = getchar();
  int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, a[1010], sum = 0;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 2; i < n; i++)
    if ((a[i] > a[i - 1] && a[i] > a[i + 1]) ||
        (a[i] < a[i - 1] && a[i] < a[i + 1]))
      sum++;
  cout << sum;
  return 0;
}
