#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int ar[N];
int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  for (int i = 1; i < n - 1; i++) {
    int a = ar[i - 1], b = ar[i], c = ar[i + 1];
    if (a > b && b < c)
      ans++;
    else if (b > a && b > c)
      ans++;
  }
  cout << ans;
}
