#include <bits/stdc++.h>
using namespace std;
int a[100001];
int ans;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 2; i <= n - 1; i++) {
    if (a[i] > a[i - 1] && a[i] > a[i + 1]) ans++;
    if (a[i] < a[i - 1] && a[i] < a[i + 1]) ans++;
  }
  cout << ans;
}
