#include <bits/stdc++.h>
using namespace std;
const int N = 1020;
int q[N], n, res;
int main()
{
cin >> n;
for (int i = 1; i <= n; i ++) cin >> q[i];
for (int i = 2; i < n; i ++)
if ((q[i - 1] < q[i] && q[i] > q[i + 1]) || (q[i - 1] > q[i] && q[i] < q[i + 1]))
res ++;
cout << res << endl;
return 0;
}