#include <bits/stdc++.h>
using namespace std;
const int maxn(1005);
int a[maxn];
int main() {
  int n;
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int ans = 0;
    for (int i = 1; i < n - 1; i++) {
      if (a[i] == a[i - 1] || a[i] == a[i + 1])
        ;
      else if ((a[i] - a[i - 1] >> 31) ^ (a[i] - a[i + 1] >> 31))
        ;
      else
        ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
