#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 20, mod = (int)(1e9) + 7;
long long arr[N];
int main() {
  int T;
  scanf("%d", &T);
  int arr[T];
  for (int i = 0; i < T; i++) cin >> arr[i];
  int count = 0;
  for (int i = 1; i < T - 1; i++)
    if ((arr[i] > arr[i - 1] and arr[i + 1] < arr[i]) ||
        (arr[i] < arr[i - 1] and arr[i + 1] > arr[i]))
      count++;
  cout << count << endl;
  return (0);
}
