#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 7;
const long long mod = 1e9 + 7;
int a[N];
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 2; i < n; ++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 << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
