#include <bits/stdc++.h>
using namespace std;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const double EPS = 1e-5;
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  vector<int> num(n);
  for (int i = 0; i < n; i++) {
    cin >> num[i];
  }
  int r = 0;
  for (int i = 1; i < n - 1; i++) {
    if (num[i] < num[i - 1] && num[i] < num[i + 1] ||
        num[i] > num[i - 1] && num[i] > num[i + 1])
      r++;
  }
  cout << r << endl;
  cin.ignore(), cin.get();
}
