import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
T[] Reads(T)() { return readln.split.to!(T[]); }
alias reads = Reads!(int);

void scan(Args...)(ref Args args) {
    import std.conv : parse;
    string[] ss = readln.split;
    int i;
    foreach (ref arg ; args)
        arg = ss[i++].parse!int;
}

void main() {
    int n; scan(n);
    int[] p = reads();
    int ans;
    foreach (i; 0..n-2) {
        int[] a = [p[i],p[i+1],p[i+2]].sort().array;
        ans += a[1] == p[i+1];
    }
    writeln(ans);
}
