#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long double PI = 3.141592653589793;
const long long int INF = 9223372036854775807ll;
void solve() {
  int n, ans = 0;
  cin >> n;
  int A[n];
  for (int i = 0; i < n; i++) cin >> A[i];
  for (int i = 1; i < n - 1; i++) {
    if (A[i] > A[i - 1] && A[i] > A[i + 1])
      ans++;
    else if (A[i] < A[i - 1] && A[i] < A[i + 1])
      ans++;
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
