import std.stdio, std.string, std.conv;

void main() {
    int n = readln.chomp.to!int;
    int[] p = readln.split.to!(int[]);
    int cnt;
    foreach (i; 1 .. n-1) {
        if (p[i-1] < p[i] && p[i] < p[i+1]) ++cnt;
        if (p[i-1] > p[i] && p[i] > p[i+1]) ++cnt;
    }
    cnt.writeln;
}