import std.algorithm;
import std.array;
import std.bigint;
import std.bitmanip;
import std.conv;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }

T[] readToArray(T)() {
    return readln.split.to!(T[]);
}

void readInto(T...)(ref T ts) {
    auto ss = readln.split;
    foreach(ref t; ts) {
        t = ss.front.to!(typeof(t));
        ss.popFront;
    }
}

void main() {
    ulong n;
    readInto(n);
    ulong[] p = readToArray!(ulong);
    ulong cnt = 0;

    for(ulong i = 1; i < p.length-1; i++) {
        //writefln("%d %d %d", p[i-1], p[i], p[i+1]);
        if(p[i-1] < p[i] && p[i] < p[i+1]) cnt++;
        else if (p[i+1] < p[i] && p[i] < p[i-1]) cnt++;
    }
    writeln(cnt);
}
