#include <iostream>
using namespace std;
const int N = 1010;
int q[N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> q[i];
}
int res = 0;
for (int i = 1; i < n - 1; ++i) {
int a = q[i], b = q[i-1], c = q[i+1];
if ((a > b && a > c) || (a < b && a < c)) {
++res;
}
}
cout << res << endl;
return 0;
}