import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++) {
            p[i] = scan.nextInt();
        }

        int cnt = 0;
        for(int i = 1; i < n -1; i++) {
            int a = p[i - 1];
            int b = p[i];
            int c = p[i + 1];

            int max = Math.max(Math.max(a, b), Math.max(a, c));
            int min = Math.min(Math.min(a, b), Math.min(a, c));
            if (max != b && min != b) {
                cnt++;
            }

        }
        System.out.println(cnt);
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++) {
            p[i] = scan.nextInt();
        }

        int cnt = 0;
        for(int i = 1; i < n -1; i++) {
            int a = p[i - 1];
            int b = p[i];
            int c = p[i + 1];

            int max = Math.max(Math.max(a, b), Math.max(a, c));
            int min = Math.min(Math.min(a, b), Math.min(a, c));
            if (max != b && min != b) {
                cnt++;
            }

        }
        System.out.println(cnt);
    }
} Main public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++) {
            p[i] = scan.nextInt();
        }

        int cnt = 0;
        for(int i = 1; i < n -1; i++) {
            int a = p[i - 1];
            int b = p[i];
            int c = p[i + 1];

            int max = Math.max(Math.max(a, b), Math.max(a, c));
            int min = Math.min(Math.min(a, b), Math.min(a, c));
            if (max != b && min != b) {
                cnt++;
            }

        }
        System.out.println(cnt);
    } main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++) {
            p[i] = scan.nextInt();
        }

        int cnt = 0;
        for(int i = 1; i < n -1; i++) {
            int a = p[i - 1];
            int b = p[i];
            int c = p[i + 1];

            int max = Math.max(Math.max(a, b), Math.max(a, c));
            int min = Math.min(Math.min(a, b), Math.min(a, c));
            if (max != b && min != b) {
                cnt++;
            }

        }
        System.out.println(cnt);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] p = new int[n]; p new int[n] n for(int i = 0; i < n; i++) {
            p[i] = scan.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            p[i] = scan.nextInt();
        } {
            p[i] = scan.nextInt();
        } p[i] = scan.nextInt() p[i] p i scan.nextInt() scan.nextInt scan int cnt = 0; cnt 0 for(int i = 1; i < n -1; i++) {
            int a = p[i - 1];
            int b = p[i];
            int c = p[i + 1];

            int max = Math.max(Math.max(a, b), Math.max(a, c));
            int min = Math.min(Math.min(a, b), Math.min(a, c));
            if (max != b && min != b) {
                cnt++;
            }

        } int i = 1; int i = 1; i 1 i < n -1 i n -1 n 1 i++ i++ i {
            int a = p[i - 1];
            int b = p[i];
            int c = p[i + 1];

            int max = Math.max(Math.max(a, b), Math.max(a, c));
            int min = Math.min(Math.min(a, b), Math.min(a, c));
            if (max != b && min != b) {
                cnt++;
            }

        } {
            int a = p[i - 1];
            int b = p[i];
            int c = p[i + 1];

            int max = Math.max(Math.max(a, b), Math.max(a, c));
            int min = Math.min(Math.min(a, b), Math.min(a, c));
            if (max != b && min != b) {
                cnt++;
            }

        } int a = p[i - 1]; a p[i - 1] p i - 1 i 1 int b = p[i]; b p[i] p i int c = p[i + 1]; c p[i + 1] p i + 1 i 1 int max = Math.max(Math.max(a, b), Math.max(a, c)); max Math.max(Math.max(a, b), Math.max(a, c)) Math.max Math Math.max(a, b) Math.max Math a b Math.max(a, c) Math.max Math a c int min = Math.min(Math.min(a, b), Math.min(a, c)); min Math.min(Math.min(a, b), Math.min(a, c)) Math.min Math Math.min(a, b) Math.min Math a b Math.min(a, c) Math.min Math a c if (max != b && min != b) {
                cnt++;
            } max != b && min != b max != b max b min != b min b {
                cnt++;
            } cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt final String[] args args
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++) {
            p[i] = scan.nextInt();
        }

        int cnt = 0;
        for(int i = 1; i < n -1; i++) {
            int a = p[i - 1];
            int b = p[i];
            int c = p[i + 1];

            int max = Math.max(Math.max(a, b), Math.max(a, c));
            int min = Math.min(Math.min(a, b), Math.min(a, c));
            if (max != b && min != b) {
                cnt++;
            }

        }
        System.out.println(cnt);
    }
}