#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
long long int fib(long long int n) {
  if (n == 0 || n == 1) {
    return 1;
  } else {
    long long int arr[n + 1];
    arr[0] = 0;
    arr[1] = 1;
    for (long long int i = 2; i <= n; i++) {
      arr[i] = arr[i - 1] + arr[i - 2];
    }
    return arr[n];
  }
}
long long int mpow(long long int base, long long int exp) {
  base %= 1000000007;
  long long int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((long long int)result * base) % 1000000007;
    base = ((long long int)base * base) % 1000000007;
    exp >>= 1;
  }
  return result;
}
long long int is_prime(long long int a) {
  long long int i;
  if (a == 2 || a == 3)
    return 1;
  else
    for (i = 2; i * i <= a; i++) {
      if (a % i == 0) return 0;
    }
  return 1;
}
long long int countSetBits(long long int n) {
  if (n == 0)
    return 0;
  else
    return (n & 1) + countSetBits(n >> 1);
}
long long int XOR(long long int n) {
  switch (n & 3) {
    case 0:
      return n;
    case 1:
      return 1;
    case 2:
      return n + 1;
    case 3:
      return 0;
  }
}
void swap(long long int x, long long int y) {
  x ^= y;
  y ^= x;
  x ^= y;
}
long long int digsum(long long int n) { return floor(log10(n)) + 1; }
bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); }
long long int binsearch(long long int arr[], long long int l, long long int r,
                        long long int no) {
  while (l <= r) {
    long long int mid = (l + r) / 2;
    if (arr[mid] == no) {
      return mid;
    } else if (arr[mid] < no) {
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  return -1;
}
long long int binomialCoeff(long long int n, long long int k) {
  if (k == 0 || k == n) return 1;
  return binomialCoeff(n - 1, k - 1) + binomialCoeff(n - 1, k);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i = 0, j = 0;
  long long int n;
  cin >> n;
  long long int arr[n];
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long int cnt = 0;
  for (long long int i = 1; i < n - 1; i++) {
    if ((arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) ||
        (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]))
      cnt++;
  }
  cout << cnt;
}
