#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long answer = 0;
  for (int i = 2; i <= n - 1; i++) {
    if (a[i] > a[i - 1] && a[i] > a[i + 1]) {
      answer++;
    }
    if (a[i] < a[i - 1] && a[i] < a[i + 1]) {
      answer++;
    }
  }
  cout << answer;
  return 0;
}
