
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];
        int cnt = 0;

        for (int i = 0; i < N; i++) p[i] = sc.nextInt();

        for (int j = 1; j < N - 1; j++) {
            if (p[j] < p[j + 1] && p[j] > p[j - 1])
                cnt++;
            else if (p[j] > p[j + 1] && p[j] < p[j - 1])
                cnt++;
        }

        System.out.println(cnt);

    }
}
 import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];
        int cnt = 0;

        for (int i = 0; i < N; i++) p[i] = sc.nextInt();

        for (int j = 1; j < N - 1; j++) {
            if (p[j] < p[j + 1] && p[j] > p[j - 1])
                cnt++;
            else if (p[j] > p[j + 1] && p[j] < p[j - 1])
                cnt++;
        }

        System.out.println(cnt);

    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];
        int cnt = 0;

        for (int i = 0; i < N; i++) p[i] = sc.nextInt();

        for (int j = 1; j < N - 1; j++) {
            if (p[j] < p[j + 1] && p[j] > p[j - 1])
                cnt++;
            else if (p[j] > p[j + 1] && p[j] < p[j - 1])
                cnt++;
        }

        System.out.println(cnt);

    } main {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];
        int cnt = 0;

        for (int i = 0; i < N; i++) p[i] = sc.nextInt();

        for (int j = 1; j < N - 1; j++) {
            if (p[j] < p[j + 1] && p[j] > p[j - 1])
                cnt++;
            else if (p[j] > p[j + 1] && p[j] < p[j - 1])
                cnt++;
        }

        System.out.println(cnt);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] p = new int[N]; p new int[N] N int cnt = 0; cnt 0 for (int i = 0; i < N; i++) p[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < N i N i++ i++ i p[i] = sc.nextInt(); p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc for (int j = 1; j < N - 1; j++) {
            if (p[j] < p[j + 1] && p[j] > p[j - 1])
                cnt++;
            else if (p[j] > p[j + 1] && p[j] < p[j - 1])
                cnt++;
        } int j = 1; int j = 1; j 1 j < N - 1 j N - 1 N 1 j++ j++ j {
            if (p[j] < p[j + 1] && p[j] > p[j - 1])
                cnt++;
            else if (p[j] > p[j + 1] && p[j] < p[j - 1])
                cnt++;
        } {
            if (p[j] < p[j + 1] && p[j] > p[j - 1])
                cnt++;
            else if (p[j] > p[j + 1] && p[j] < p[j - 1])
                cnt++;
        } if (p[j] < p[j + 1] && p[j] > p[j - 1])
                cnt++;
            else if (p[j] > p[j + 1] && p[j] < p[j - 1])
                cnt++; p[j] < p[j + 1] && p[j] > p[j - 1] p[j] < p[j + 1] p[j] p j p[j + 1] p j + 1 j 1 p[j] > p[j - 1] p[j] p j p[j - 1] p j - 1 j 1 cnt++ cnt if (p[j] > p[j + 1] && p[j] < p[j - 1])
                cnt++; p[j] > p[j + 1] && p[j] < p[j - 1] p[j] > p[j + 1] p[j] p j p[j + 1] p j + 1 j 1 p[j] < p[j - 1] p[j] p j p[j - 1] p j - 1 j 1 cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];
        int cnt = 0;

        for (int i = 0; i < N; i++) p[i] = sc.nextInt();

        for (int j = 1; j < N - 1; j++) {
            if (p[j] < p[j + 1] && p[j] > p[j - 1])
                cnt++;
            else if (p[j] > p[j + 1] && p[j] < p[j - 1])
                cnt++;
        }

        System.out.println(cnt);

    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];
        int cnt = 0;

        for (int i = 0; i < N; i++) p[i] = sc.nextInt();

        for (int j = 1; j < N - 1; j++) {
            if (p[j] < p[j + 1] && p[j] > p[j - 1])
                cnt++;
            else if (p[j] > p[j + 1] && p[j] < p[j - 1])
                cnt++;
        }

        System.out.println(cnt);

    }
} Main

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];
        int cnt = 0;

        for (int i = 0; i < N; i++) p[i] = sc.nextInt();

        for (int j = 1; j < N - 1; j++) {
            if (p[j] < p[j + 1] && p[j] > p[j - 1])
                cnt++;
            else if (p[j] > p[j + 1] && p[j] < p[j - 1])
                cnt++;
        }

        System.out.println(cnt);

    }
}

