#include <bits/stdc++.h>
using namespace std;
const int MAXN = 16;
signed main() {
  vector<int> a;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int temp;
    cin >> temp;
    a.push_back(temp);
  }
  int ans = 0;
  for (int i = 1; i < n - 1; ++i) {
    ans += (a[i] > a[i - 1] && a[i] > a[i + 1] ||
            a[i] < a[i - 1] && a[i] < a[i + 1]);
  }
  cout << ans;
  return 0;
}
