#include <bits/stdc++.h>
using namespace std;
template <class C>
void min_self(C &a, C b) {
  a = min(a, b);
}
template <class C>
void max_self(C &a, C b) {
  a = max(a, b);
}
const long long MOD = 1000000007;
long long mod(long long n, long long m = MOD) {
  n %= m, n += m, n %= m;
  return n;
}
const int MAXN = 1e5 + 5;
const int LOGN = 21;
const long long INF = 1e14;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  int res = 0;
  for (int i = 1; i < n - 1; ++i) {
    if (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]) {
      res++;
    }
    if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) {
      res++;
    }
  }
  cout << res << "\n";
}
