#include <bits/stdc++.h>
using namespace std;
long double pie = 3.141592653589793238462643383279;
long long mod = 1e9 + 7;
long long dx[] = {-1, 1, 0, 0};
long long dy[] = {0, 0, 1, -1};
vector<long long> adj[1000005];
long long a[1000005];
long long n, m;
long long lp = 0;
void dfs(long long s, long long c, long long p) {
  if (c > m) return;
  if (a[s] == 0) c = 0;
  bool leaf = 1;
  for (auto it : adj[s]) {
    if (it != p) {
      if (a[it] == 1)
        dfs(it, c + 1, s);
      else
        dfs(it, c, s);
      leaf = 0;
    }
  }
  lp += leaf;
}
bool ispallin(string s) {
  long long xp = s.size();
  for (long long i = 0; i < (long long)xp; ++i)
    if (s[i] != s[xp - 1 - i]) return 0;
  return 1;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (long long i = 0; i < (long long)n; ++i) cin >> a[i];
  for (long long i = 1; i < (long long)n - 1; ++i) {
    if (a[i] > a[i - 1] && a[i] > a[i + 1]) ++lp;
    if (a[i] < a[i - 1] && a[i] < a[i + 1]) ++lp;
  }
  cout << lp;
  return 0;
}
