"use strict";
const main = input => {
    const n = parseInt(input[0],10);
    const p = input[1].split(' ');
    let ans=0;
    for(let i=0; i<n; i++) {
        p[i] = parseInt(p[i], 10);
    }
    for(let i=1; i<n-1; i++) {
        if ((p[i]>p[i-1] && p[i]<p[i+1]) || (p[i]<p[i-1] && p[i]>p[i+1])) {
            ans++;
        }
    }
    console.log(ans);
    
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));