"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const p = arg[1].split(" ").map(n=>parseInt(n));
    
    let answer = 0;
    
    for(let i=0; i<N-2; i++) {
        let left   = p[i];
        let middle = p[parseInt(i) + 1];
        let right  = p[parseInt(i) + 2];
        
        let array = [left, middle, right].sort((a,b)=>a-b);
        
        if(array[1] === middle) {
            answer++;
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));