#include <bits/stdc++.h>
using namespace std;
long long func(long long arr[], long long n) {
  long long ans = 0;
  for (long long i = 2; i < n; i++) {
    if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) {
      ans++;
    } else if (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]) {
      ans++;
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long arr[n + 1];
  for (long long i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  cout << func(arr, n) << endl;
}
