#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1010;
int n;
int a[N];
int main()
{
cin>>n;
for(int i = 0; i<n; i++) cin>>a[i];
int ans = 0;
for(int i = 1; i+1<n; i++)
{
if((a[i]<a[i-1]&&a[i]<a[i+1]) || (a[i]>a[i-1]&&a[i]>a[i+1]))
ans++;
}
cout<<ans;
return 0;
}