import java.util.Scanner;

public class Main {
    //Ordinary Number
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++) A[i] = sc.nextInt();
        System.out.println(sln(A));
        sc.close();
    }

    static int sln(int[] A) {
        int n = A.length, res = 0;
        for (int i = 1; i < n - 1; i++) {
            if ((A[i] <= A[i - 1] && A[i] <= A[i + 1]) || (A[i] >= A[i - 1] && A[i] >= A[i + 1])) continue;
            res++;
        }
        return res;
    }
} import java.util.Scanner; Scanner java.util public class Main {
    //Ordinary Number
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++) A[i] = sc.nextInt();
        System.out.println(sln(A));
        sc.close();
    }

    static int sln(int[] A) {
        int n = A.length, res = 0;
        for (int i = 1; i < n - 1; i++) {
            if ((A[i] <= A[i - 1] && A[i] <= A[i + 1]) || (A[i] >= A[i - 1] && A[i] >= A[i + 1])) continue;
            res++;
        }
        return res;
    }
} Main //Ordinary Number
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++) A[i] = sc.nextInt();
        System.out.println(sln(A));
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++) A[i] = sc.nextInt();
        System.out.println(sln(A));
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] A = new int[n]; A new int[n] n for (int i = 0; i < n; i++) A[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i A[i] = sc.nextInt(); A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc System.out.println(sln(A)) System.out.println System.out System System.out sln(A) sln A sc.close() sc.close sc String[] args args static int sln(int[] A) {
        int n = A.length, res = 0;
        for (int i = 1; i < n - 1; i++) {
            if ((A[i] <= A[i - 1] && A[i] <= A[i + 1]) || (A[i] >= A[i - 1] && A[i] >= A[i + 1])) continue;
            res++;
        }
        return res;
    } sln {
        int n = A.length, res = 0;
        for (int i = 1; i < n - 1; i++) {
            if ((A[i] <= A[i - 1] && A[i] <= A[i + 1]) || (A[i] >= A[i - 1] && A[i] >= A[i + 1])) continue;
            res++;
        }
        return res;
    } int n = A.length n A.length A A.length res = 0; res 0 for (int i = 1; i < n - 1; i++) {
            if ((A[i] <= A[i - 1] && A[i] <= A[i + 1]) || (A[i] >= A[i - 1] && A[i] >= A[i + 1])) continue;
            res++;
        } int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i {
            if ((A[i] <= A[i - 1] && A[i] <= A[i + 1]) || (A[i] >= A[i - 1] && A[i] >= A[i + 1])) continue;
            res++;
        } {
            if ((A[i] <= A[i - 1] && A[i] <= A[i + 1]) || (A[i] >= A[i - 1] && A[i] >= A[i + 1])) continue;
            res++;
        } if ((A[i] <= A[i - 1] && A[i] <= A[i + 1]) || (A[i] >= A[i - 1] && A[i] >= A[i + 1])) continue; (A[i] <= A[i - 1] && A[i] <= A[i + 1]) || (A[i] >= A[i - 1] && A[i] >= A[i + 1]) (A[i] <= A[i - 1] && A[i] <= A[i + 1]) A[i] <= A[i - 1] A[i] A i A[i - 1] A i - 1 i 1 A[i] <= A[i + 1] A[i] A i A[i + 1] A i + 1 i 1 (A[i] >= A[i - 1] && A[i] >= A[i + 1]) A[i] >= A[i - 1] A[i] A i A[i - 1] A i - 1 i 1 A[i] >= A[i + 1] A[i] A i A[i + 1] A i + 1 i 1 continue; res++ res return res; res int[] A A public class Main {
    //Ordinary Number
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++) A[i] = sc.nextInt();
        System.out.println(sln(A));
        sc.close();
    }

    static int sln(int[] A) {
        int n = A.length, res = 0;
        for (int i = 1; i < n - 1; i++) {
            if ((A[i] <= A[i - 1] && A[i] <= A[i + 1]) || (A[i] >= A[i - 1] && A[i] >= A[i + 1])) continue;
            res++;
        }
        return res;
    }
} public class Main {
    //Ordinary Number
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++) A[i] = sc.nextInt();
        System.out.println(sln(A));
        sc.close();
    }

    static int sln(int[] A) {
        int n = A.length, res = 0;
        for (int i = 1; i < n - 1; i++) {
            if ((A[i] <= A[i - 1] && A[i] <= A[i + 1]) || (A[i] >= A[i - 1] && A[i] >= A[i + 1])) continue;
            res++;
        }
        return res;
    }
} Main
import java.util.Scanner;

public class Main {
    //Ordinary Number
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++) A[i] = sc.nextInt();
        System.out.println(sln(A));
        sc.close();
    }

    static int sln(int[] A) {
        int n = A.length, res = 0;
        for (int i = 1; i < n - 1; i++) {
            if ((A[i] <= A[i - 1] && A[i] <= A[i + 1]) || (A[i] >= A[i - 1] && A[i] >= A[i + 1])) continue;
            res++;
        }
        return res;
    }
}
