import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = readInt(reader);
            int[] P = readIntArray(reader);

            int c = 0;
            for (int i = 1; i < N - 1; i++) {
                if (P[i - 1] < P[i] && P[i] < P[i + 1]) {
                    c++;
                } else if (P[i - 1] > P[i] && P[i] > P[i + 1]) {
                    c++;
                }
            }

            System.out.println(c);
        }
    }

    public static String readString(BufferedReader reader) throws Exception {
        return reader.readLine();
    }

    public static int readInt(BufferedReader reader) throws Exception {
        return Integer.parseInt(reader.readLine());
    }

    public static long readLong(BufferedReader reader) throws Exception {
        return Long.parseLong(reader.readLine());
    }

    public static double readDouble(BufferedReader reader) throws Exception {
        return Double.parseDouble(reader.readLine());
    }

    public static String[] readStringArray(BufferedReader reader) throws Exception {
        return reader.readLine().split(" ");
    }

    public static int[] readIntArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    }

    public static long[] readLongArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        long[] array = new long[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Long.parseLong(str[i]);
        }
        return array;
    }

    public static double[] readDoubleArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        double[] array = new double[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Double.parseDouble(str[i]);
        }
        return array;
    }

    public static int[][] readIntMatrix(BufferedReader reader, int N) throws Exception {
        int[][] matrix = new int[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readIntArray(reader);
        }
        return matrix;
    }

    public static long[][] readLongMatrix(BufferedReader reader, int N) throws Exception {
        long[][] matrix = new long[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readLongArray(reader);
        }
        return matrix;
    }

    public static double[][] readDoubleMatrix(BufferedReader reader, int N) throws Exception {
        double[][] matrix = new double[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readDoubleArray(reader);
        }
        return matrix;
    }

    public static int[] extractArray(int[][] matrix, int index) {
        int[] array = new int[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    }

    public static long[] extractArray(long[][] matrix, int index) {
        long[] array = new long[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    }

    public static double[] extractArray(double[][] matrix, int index) {
        double[] array = new double[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    }

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = readInt(reader);
            int[] P = readIntArray(reader);

            int c = 0;
            for (int i = 1; i < N - 1; i++) {
                if (P[i - 1] < P[i] && P[i] < P[i + 1]) {
                    c++;
                } else if (P[i - 1] > P[i] && P[i] > P[i + 1]) {
                    c++;
                }
            }

            System.out.println(c);
        }
    }

    public static String readString(BufferedReader reader) throws Exception {
        return reader.readLine();
    }

    public static int readInt(BufferedReader reader) throws Exception {
        return Integer.parseInt(reader.readLine());
    }

    public static long readLong(BufferedReader reader) throws Exception {
        return Long.parseLong(reader.readLine());
    }

    public static double readDouble(BufferedReader reader) throws Exception {
        return Double.parseDouble(reader.readLine());
    }

    public static String[] readStringArray(BufferedReader reader) throws Exception {
        return reader.readLine().split(" ");
    }

    public static int[] readIntArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    }

    public static long[] readLongArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        long[] array = new long[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Long.parseLong(str[i]);
        }
        return array;
    }

    public static double[] readDoubleArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        double[] array = new double[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Double.parseDouble(str[i]);
        }
        return array;
    }

    public static int[][] readIntMatrix(BufferedReader reader, int N) throws Exception {
        int[][] matrix = new int[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readIntArray(reader);
        }
        return matrix;
    }

    public static long[][] readLongMatrix(BufferedReader reader, int N) throws Exception {
        long[][] matrix = new long[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readLongArray(reader);
        }
        return matrix;
    }

    public static double[][] readDoubleMatrix(BufferedReader reader, int N) throws Exception {
        double[][] matrix = new double[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readDoubleArray(reader);
        }
        return matrix;
    }

    public static int[] extractArray(int[][] matrix, int index) {
        int[] array = new int[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    }

    public static long[] extractArray(long[][] matrix, int index) {
        long[] array = new long[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    }

    public static double[] extractArray(double[][] matrix, int index) {
        double[] array = new double[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    }

} Main public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = readInt(reader);
            int[] P = readIntArray(reader);

            int c = 0;
            for (int i = 1; i < N - 1; i++) {
                if (P[i - 1] < P[i] && P[i] < P[i + 1]) {
                    c++;
                } else if (P[i - 1] > P[i] && P[i] > P[i + 1]) {
                    c++;
                }
            }

            System.out.println(c);
        }
    } main {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = readInt(reader);
            int[] P = readIntArray(reader);

            int c = 0;
            for (int i = 1; i < N - 1; i++) {
                if (P[i - 1] < P[i] && P[i] < P[i + 1]) {
                    c++;
                } else if (P[i - 1] > P[i] && P[i] > P[i + 1]) {
                    c++;
                }
            }

            System.out.println(c);
        }
    } try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = readInt(reader);
            int[] P = readIntArray(reader);

            int c = 0;
            for (int i = 1; i < N - 1; i++) {
                if (P[i - 1] < P[i] && P[i] < P[i + 1]) {
                    c++;
                } else if (P[i - 1] > P[i] && P[i] > P[i + 1]) {
                    c++;
                }
            }

            System.out.println(c);
        } {
            int N = readInt(reader);
            int[] P = readIntArray(reader);

            int c = 0;
            for (int i = 1; i < N - 1; i++) {
                if (P[i - 1] < P[i] && P[i] < P[i + 1]) {
                    c++;
                } else if (P[i - 1] > P[i] && P[i] > P[i + 1]) {
                    c++;
                }
            }

            System.out.println(c);
        } BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)) BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) int N = readInt(reader); N readInt(reader) readInt reader int[] P = readIntArray(reader); P readIntArray(reader) readIntArray reader int c = 0; c 0 for (int i = 1; i < N - 1; i++) {
                if (P[i - 1] < P[i] && P[i] < P[i + 1]) {
                    c++;
                } else if (P[i - 1] > P[i] && P[i] > P[i + 1]) {
                    c++;
                }
            } int i = 1; int i = 1; i 1 i < N - 1 i N - 1 N 1 i++ i++ i {
                if (P[i - 1] < P[i] && P[i] < P[i + 1]) {
                    c++;
                } else if (P[i - 1] > P[i] && P[i] > P[i + 1]) {
                    c++;
                }
            } {
                if (P[i - 1] < P[i] && P[i] < P[i + 1]) {
                    c++;
                } else if (P[i - 1] > P[i] && P[i] > P[i + 1]) {
                    c++;
                }
            } if (P[i - 1] < P[i] && P[i] < P[i + 1]) {
                    c++;
                } else if (P[i - 1] > P[i] && P[i] > P[i + 1]) {
                    c++;
                } P[i - 1] < P[i] && P[i] < P[i + 1] P[i - 1] < P[i] P[i - 1] P i - 1 i 1 P[i] P i P[i] < P[i + 1] P[i] P i P[i + 1] P i + 1 i 1 {
                    c++;
                } c++ c if (P[i - 1] > P[i] && P[i] > P[i + 1]) {
                    c++;
                } P[i - 1] > P[i] && P[i] > P[i + 1] P[i - 1] > P[i] P[i - 1] P i - 1 i 1 P[i] P i P[i] > P[i + 1] P[i] P i P[i + 1] P i + 1 i 1 {
                    c++;
                } c++ c System.out.println(c) System.out.println System.out System System.out c String[] args args public static String readString(BufferedReader reader) throws Exception {
        return reader.readLine();
    } readString {
        return reader.readLine();
    } return reader.readLine(); reader.readLine() reader.readLine reader BufferedReader reader reader public static int readInt(BufferedReader reader) throws Exception {
        return Integer.parseInt(reader.readLine());
    } readInt {
        return Integer.parseInt(reader.readLine());
    } return Integer.parseInt(reader.readLine()); Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader BufferedReader reader reader public static long readLong(BufferedReader reader) throws Exception {
        return Long.parseLong(reader.readLine());
    } readLong {
        return Long.parseLong(reader.readLine());
    } return Long.parseLong(reader.readLine()); Long.parseLong(reader.readLine()) Long.parseLong Long reader.readLine() reader.readLine reader BufferedReader reader reader public static double readDouble(BufferedReader reader) throws Exception {
        return Double.parseDouble(reader.readLine());
    } readDouble {
        return Double.parseDouble(reader.readLine());
    } return Double.parseDouble(reader.readLine()); Double.parseDouble(reader.readLine()) Double.parseDouble Double reader.readLine() reader.readLine reader BufferedReader reader reader public static String[] readStringArray(BufferedReader reader) throws Exception {
        return reader.readLine().split(" ");
    } readStringArray {
        return reader.readLine().split(" ");
    } return reader.readLine().split(" "); reader.readLine().split(" ") reader.readLine().split reader.readLine() reader.readLine reader " " BufferedReader reader reader public static int[] readIntArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    } readIntArray {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    } String[] str = reader.readLine().split(" "); str reader.readLine().split(" ") reader.readLine().split reader.readLine() reader.readLine reader " " int[] array = new int[str.length]; array new int[str.length] str.length str str.length for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        } int i = 0; int i = 0; i 0 i < str.length i str.length str str.length i++ i++ i {
            array[i] = Integer.parseInt(str[i]);
        } {
            array[i] = Integer.parseInt(str[i]);
        } array[i] = Integer.parseInt(str[i]) array[i] array i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i return array; array BufferedReader reader reader public static long[] readLongArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        long[] array = new long[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Long.parseLong(str[i]);
        }
        return array;
    } readLongArray {
        String[] str = reader.readLine().split(" ");
        long[] array = new long[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Long.parseLong(str[i]);
        }
        return array;
    } String[] str = reader.readLine().split(" "); str reader.readLine().split(" ") reader.readLine().split reader.readLine() reader.readLine reader " " long[] array = new long[str.length]; array new long[str.length] str.length str str.length for (int i = 0; i < str.length; i++) {
            array[i] = Long.parseLong(str[i]);
        } int i = 0; int i = 0; i 0 i < str.length i str.length str str.length i++ i++ i {
            array[i] = Long.parseLong(str[i]);
        } {
            array[i] = Long.parseLong(str[i]);
        } array[i] = Long.parseLong(str[i]) array[i] array i Long.parseLong(str[i]) Long.parseLong Long str[i] str i return array; array BufferedReader reader reader public static double[] readDoubleArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        double[] array = new double[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Double.parseDouble(str[i]);
        }
        return array;
    } readDoubleArray {
        String[] str = reader.readLine().split(" ");
        double[] array = new double[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Double.parseDouble(str[i]);
        }
        return array;
    } String[] str = reader.readLine().split(" "); str reader.readLine().split(" ") reader.readLine().split reader.readLine() reader.readLine reader " " double[] array = new double[str.length]; array new double[str.length] str.length str str.length for (int i = 0; i < str.length; i++) {
            array[i] = Double.parseDouble(str[i]);
        } int i = 0; int i = 0; i 0 i < str.length i str.length str str.length i++ i++ i {
            array[i] = Double.parseDouble(str[i]);
        } {
            array[i] = Double.parseDouble(str[i]);
        } array[i] = Double.parseDouble(str[i]) array[i] array i Double.parseDouble(str[i]) Double.parseDouble Double str[i] str i return array; array BufferedReader reader reader public static int[][] readIntMatrix(BufferedReader reader, int N) throws Exception {
        int[][] matrix = new int[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readIntArray(reader);
        }
        return matrix;
    } readIntMatrix {
        int[][] matrix = new int[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readIntArray(reader);
        }
        return matrix;
    } int[][] matrix = new int[N][]; matrix new int[N][] N for (int i = 0; i < N; i++) {
            matrix[i] = readIntArray(reader);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            matrix[i] = readIntArray(reader);
        } {
            matrix[i] = readIntArray(reader);
        } matrix[i] = readIntArray(reader) matrix[i] matrix i readIntArray(reader) readIntArray reader return matrix; matrix BufferedReader reader reader int N N public static long[][] readLongMatrix(BufferedReader reader, int N) throws Exception {
        long[][] matrix = new long[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readLongArray(reader);
        }
        return matrix;
    } readLongMatrix {
        long[][] matrix = new long[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readLongArray(reader);
        }
        return matrix;
    } long[][] matrix = new long[N][]; matrix new long[N][] N for (int i = 0; i < N; i++) {
            matrix[i] = readLongArray(reader);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            matrix[i] = readLongArray(reader);
        } {
            matrix[i] = readLongArray(reader);
        } matrix[i] = readLongArray(reader) matrix[i] matrix i readLongArray(reader) readLongArray reader return matrix; matrix BufferedReader reader reader int N N public static double[][] readDoubleMatrix(BufferedReader reader, int N) throws Exception {
        double[][] matrix = new double[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readDoubleArray(reader);
        }
        return matrix;
    } readDoubleMatrix {
        double[][] matrix = new double[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readDoubleArray(reader);
        }
        return matrix;
    } double[][] matrix = new double[N][]; matrix new double[N][] N for (int i = 0; i < N; i++) {
            matrix[i] = readDoubleArray(reader);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            matrix[i] = readDoubleArray(reader);
        } {
            matrix[i] = readDoubleArray(reader);
        } matrix[i] = readDoubleArray(reader) matrix[i] matrix i readDoubleArray(reader) readDoubleArray reader return matrix; matrix BufferedReader reader reader int N N public static int[] extractArray(int[][] matrix, int index) {
        int[] array = new int[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    } extractArray {
        int[] array = new int[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    } int[] array = new int[matrix.length]; array new int[matrix.length] matrix.length matrix matrix.length for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        } int i = 0; int i = 0; i 0 i < matrix.length i matrix.length matrix matrix.length i++ i++ i {
            array[i] = matrix[i][index];
        } {
            array[i] = matrix[i][index];
        } array[i] = matrix[i][index] array[i] array i matrix[i][index] matrix[i] matrix i index return array; array int[][] matrix matrix int index index public static long[] extractArray(long[][] matrix, int index) {
        long[] array = new long[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    } extractArray {
        long[] array = new long[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    } long[] array = new long[matrix.length]; array new long[matrix.length] matrix.length matrix matrix.length for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        } int i = 0; int i = 0; i 0 i < matrix.length i matrix.length matrix matrix.length i++ i++ i {
            array[i] = matrix[i][index];
        } {
            array[i] = matrix[i][index];
        } array[i] = matrix[i][index] array[i] array i matrix[i][index] matrix[i] matrix i index return array; array long[][] matrix matrix int index index public static double[] extractArray(double[][] matrix, int index) {
        double[] array = new double[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    } extractArray {
        double[] array = new double[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    } double[] array = new double[matrix.length]; array new double[matrix.length] matrix.length matrix matrix.length for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        } int i = 0; int i = 0; i 0 i < matrix.length i matrix.length matrix matrix.length i++ i++ i {
            array[i] = matrix[i][index];
        } {
            array[i] = matrix[i][index];
        } array[i] = matrix[i][index] array[i] array i matrix[i][index] matrix[i] matrix i index return array; array double[][] matrix matrix int index index public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = readInt(reader);
            int[] P = readIntArray(reader);

            int c = 0;
            for (int i = 1; i < N - 1; i++) {
                if (P[i - 1] < P[i] && P[i] < P[i + 1]) {
                    c++;
                } else if (P[i - 1] > P[i] && P[i] > P[i + 1]) {
                    c++;
                }
            }

            System.out.println(c);
        }
    }

    public static String readString(BufferedReader reader) throws Exception {
        return reader.readLine();
    }

    public static int readInt(BufferedReader reader) throws Exception {
        return Integer.parseInt(reader.readLine());
    }

    public static long readLong(BufferedReader reader) throws Exception {
        return Long.parseLong(reader.readLine());
    }

    public static double readDouble(BufferedReader reader) throws Exception {
        return Double.parseDouble(reader.readLine());
    }

    public static String[] readStringArray(BufferedReader reader) throws Exception {
        return reader.readLine().split(" ");
    }

    public static int[] readIntArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    }

    public static long[] readLongArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        long[] array = new long[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Long.parseLong(str[i]);
        }
        return array;
    }

    public static double[] readDoubleArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        double[] array = new double[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Double.parseDouble(str[i]);
        }
        return array;
    }

    public static int[][] readIntMatrix(BufferedReader reader, int N) throws Exception {
        int[][] matrix = new int[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readIntArray(reader);
        }
        return matrix;
    }

    public static long[][] readLongMatrix(BufferedReader reader, int N) throws Exception {
        long[][] matrix = new long[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readLongArray(reader);
        }
        return matrix;
    }

    public static double[][] readDoubleMatrix(BufferedReader reader, int N) throws Exception {
        double[][] matrix = new double[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readDoubleArray(reader);
        }
        return matrix;
    }

    public static int[] extractArray(int[][] matrix, int index) {
        int[] array = new int[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    }

    public static long[] extractArray(long[][] matrix, int index) {
        long[] array = new long[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    }

    public static double[] extractArray(double[][] matrix, int index) {
        double[] array = new double[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    }

} public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = readInt(reader);
            int[] P = readIntArray(reader);

            int c = 0;
            for (int i = 1; i < N - 1; i++) {
                if (P[i - 1] < P[i] && P[i] < P[i + 1]) {
                    c++;
                } else if (P[i - 1] > P[i] && P[i] > P[i + 1]) {
                    c++;
                }
            }

            System.out.println(c);
        }
    }

    public static String readString(BufferedReader reader) throws Exception {
        return reader.readLine();
    }

    public static int readInt(BufferedReader reader) throws Exception {
        return Integer.parseInt(reader.readLine());
    }

    public static long readLong(BufferedReader reader) throws Exception {
        return Long.parseLong(reader.readLine());
    }

    public static double readDouble(BufferedReader reader) throws Exception {
        return Double.parseDouble(reader.readLine());
    }

    public static String[] readStringArray(BufferedReader reader) throws Exception {
        return reader.readLine().split(" ");
    }

    public static int[] readIntArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    }

    public static long[] readLongArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        long[] array = new long[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Long.parseLong(str[i]);
        }
        return array;
    }

    public static double[] readDoubleArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        double[] array = new double[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Double.parseDouble(str[i]);
        }
        return array;
    }

    public static int[][] readIntMatrix(BufferedReader reader, int N) throws Exception {
        int[][] matrix = new int[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readIntArray(reader);
        }
        return matrix;
    }

    public static long[][] readLongMatrix(BufferedReader reader, int N) throws Exception {
        long[][] matrix = new long[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readLongArray(reader);
        }
        return matrix;
    }

    public static double[][] readDoubleMatrix(BufferedReader reader, int N) throws Exception {
        double[][] matrix = new double[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readDoubleArray(reader);
        }
        return matrix;
    }

    public static int[] extractArray(int[][] matrix, int index) {
        int[] array = new int[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    }

    public static long[] extractArray(long[][] matrix, int index) {
        long[] array = new long[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    }

    public static double[] extractArray(double[][] matrix, int index) {
        double[] array = new double[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    }

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = readInt(reader);
            int[] P = readIntArray(reader);

            int c = 0;
            for (int i = 1; i < N - 1; i++) {
                if (P[i - 1] < P[i] && P[i] < P[i + 1]) {
                    c++;
                } else if (P[i - 1] > P[i] && P[i] > P[i + 1]) {
                    c++;
                }
            }

            System.out.println(c);
        }
    }

    public static String readString(BufferedReader reader) throws Exception {
        return reader.readLine();
    }

    public static int readInt(BufferedReader reader) throws Exception {
        return Integer.parseInt(reader.readLine());
    }

    public static long readLong(BufferedReader reader) throws Exception {
        return Long.parseLong(reader.readLine());
    }

    public static double readDouble(BufferedReader reader) throws Exception {
        return Double.parseDouble(reader.readLine());
    }

    public static String[] readStringArray(BufferedReader reader) throws Exception {
        return reader.readLine().split(" ");
    }

    public static int[] readIntArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    }

    public static long[] readLongArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        long[] array = new long[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Long.parseLong(str[i]);
        }
        return array;
    }

    public static double[] readDoubleArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        double[] array = new double[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Double.parseDouble(str[i]);
        }
        return array;
    }

    public static int[][] readIntMatrix(BufferedReader reader, int N) throws Exception {
        int[][] matrix = new int[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readIntArray(reader);
        }
        return matrix;
    }

    public static long[][] readLongMatrix(BufferedReader reader, int N) throws Exception {
        long[][] matrix = new long[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readLongArray(reader);
        }
        return matrix;
    }

    public static double[][] readDoubleMatrix(BufferedReader reader, int N) throws Exception {
        double[][] matrix = new double[N][];
        for (int i = 0; i < N; i++) {
            matrix[i] = readDoubleArray(reader);
        }
        return matrix;
    }

    public static int[] extractArray(int[][] matrix, int index) {
        int[] array = new int[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    }

    public static long[] extractArray(long[][] matrix, int index) {
        long[] array = new long[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    }

    public static double[] extractArray(double[][] matrix, int index) {
        double[] array = new double[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            array[i] = matrix[i][index];
        }
        return array;
    }

}
