'use strict'

function main(input){
    const N = Number(input[0]);
    const P = input[1].split(' ').map(Number);
    let ans = 0;
    for(let i=0;i<N-2;i++){
        if((P[i+1]-P[i])*(P[i+2]-P[i+1])>0) ans++;
    }
    console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').split('\n'))