#import <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int a=0,b=0,c=0;
    int ans=0;
    for(int i=0;i<n;i++){
        a=b;
        b=c;
        scanf("%d",&c);
        if(i<=1) continue;
        if((a<b&&b<c)||(a>b&&b>c)) ans++;
    }
    printf("%d",ans);
}
