#include <bits/stdc++.h>
using namespace std;
void fastIO() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  int n, a[1111];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int ans = 0;
  for (int i = 1; i < n - 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);
}
