#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const int MOD = 998244353LL;
template <typename T, typename U>
inline void AMIN(T &x, U y) {
  if (x > y) x = y;
}
template <typename T, typename U>
inline void AMAX(T &x, U y) {
  if (x < y) x = y;
}
int a[(int)(1e3 + 5)];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < int(n); i++) cin >> a[i];
  int num = 0;
  for (int i = 1; i <= int(n - 2); i++) {
    if (a[i - 1] > a[i] && a[i] < a[i + 1]) num++;
    if (a[i - 1] < a[i] && a[i] > a[i + 1]) num++;
  }
  cout << num << endl;
  return 0;
}
