#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < v.size();i++)

#define INF 1000000000
#define pb(a) push_back(a)
#define llong long long

int main(){
	int a[100];
	int n;
	int ans=0;
	cin>>n;
	REP(i,n){
		cin>>a[i];
	}
	REP(i,n-2){
		if(a[i]==a[i+1])continue;
		if(a[i]==a[i+2])continue;
		if(a[i+1]==a[i+2])continue;
		if((a[i]>a[i+1]&&a[i]<a[i+2])||(a[i]<a[i+1]&&a[i]>a[i+2])){
			ans++;
		}
		if((a[i+2]>a[i+1]&&a[i+2]<a[i])||(a[i+2]<a[i+1]&&a[i+2]>a[i])){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}