#include <iostream> 
#include <vector>
using namespace std;

int main() {
	int n;
	vector<int> p;
	cin >> n;

	for(int i = 0;i<n;i++){
		int a;
		cin >> a;
		p.push_back(a);
	}
	int ans=0;
	for(int i = 2;i<n;i++){
		if((p[i-2]-p[i-1])*(p[i-1]-p[i])>0)ans++;
	}
	cout << ans;
}
