#include <bits/stdc++.h>
using namespace std;
long long p[100000];
set<string> r;
set<long long> c;
set<long long>::iterator itr;
map<long long, long long> co;
map<pair<long long, long long>, long long> mp;
map<char, long long> m;
map<char, long long> mcp;
map<pair<long long, long long>, long long>::iterator it;
map<char, long long>::iterator x;
map<long long, long long>::iterator y;
map<long long, long long>::iterator z;
vector<string> v[1000000];
vector<string>::iterator itt;
stack<int> stk;
queue<int> qu;
pair<long long, long long> g;
int main() {
  long long n, count = 0;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 1; i < n - 1; i++) {
    if ((a[i] > a[i - 1] && a[i] > a[i + 1]) ||
        (a[i] < a[i - 1] && a[i] < a[i + 1]))
      count++;
  }
  cout << count;
  return 0;
}
