#include <bits/stdc++.h>
using namespace std;
int n, a[10000001], ans;
const int MOD = int(1e9) + 7;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 1; i < n - 1; i++)
    if ((a[i] - a[i + 1] > 0 && a[i] - a[i - 1] > 0) ||
        (a[i] - a[i + 1] < 0 && a[i] - a[i - 1] < 0))
      ans++;
  cout << ans;
  return 0;
}
