#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
long long int power(long long int base, long long int exp) {
  long long int res = 1;
  while (exp) {
    if (exp % 2) res *= base;
    base *= base;
    res %= mod;
    base %= mod;
    exp /= 2;
  }
  return res;
}
int arr[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, i;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> arr[i];
  int ans = 0;
  for (i = 2; i < n; i++) {
    if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) ans++;
    if (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]) ans++;
  }
  cout << ans;
  return 0;
}
