#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1e3 + 5;
int arr[N];
int main()
{
int n, ret = 0;
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &arr[i]);
for (int i = 1; i < n-1; ++i)
if ((arr[i] - arr[i-1]) * (arr[i] - arr[i+1]) > 0) ret++;
printf("%d", ret);
return 0;
}