#include <bits/stdc++.h>
using namespace std;
inline long long Readint() {
  long long ret = 0;
  int f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f *= -1;
  } while (ch >= 0 && (ch < '0' || ch > '9'));
  while ('0' <= ch && ch <= '9') {
    ret = ret * 10 + ch - '0';
    ch = getchar();
  }
  return ret * f;
}
void open() {
  freopen("A.in", "r", stdin);
  freopen("A.out", "w", stdout);
}
void close() {
  fclose(stdin);
  fclose(stdout);
}
const int MAXN = 1010;
int n;
int a[MAXN];
void init() {
  scanf("%d", &n);
  for (int i = (1), i_END_ = (n); i <= i_END_; i++) scanf("%d", &a[i]);
  int ans = 0;
  for (int i = (2), i_END_ = (n); i < i_END_; 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 << endl;
}
int main() {
  int _ = 0;
  init();
  close();
  return 0;
}
