#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 10;
int n, A[maxn];
int main() {
  cin.sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> A[i];
  int cnt = 0;
  for (int i = 2; i <= n - 1; ++i)
    if ((A[i] > A[i - 1] && A[i] > A[i + 1]) ||
        (A[i] < A[i - 1] && A[i] < A[i + 1]))
      ++cnt;
  cout << cnt << endl;
  return 0;
}
