#include <bits/stdc++.h>
using namespace std;
int N;
int A[1004];
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  for (int i = (1), _b = (N); i <= _b; ++i) cin >> A[i];
  int cnt = 0;
  for (int i = (2), _b = (N - 1); i <= _b; ++i) {
    if (A[i] < A[i - 1] && A[i] < A[i + 1])
      ++cnt;
    else if (A[i] > A[i - 1] && A[i] > A[i + 1])
      ++cnt;
  }
  cout << cnt << endl;
  return 0;
}
