import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int [] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();
        int sum = 0;
        for (int i = 1; i < n-1; i++){
            int [] new_a = {a[i-1], a[i], a[i+1]};
            Arrays.sort(new_a);
            if (new_a[1] == a[i]){
                sum++;
            }
        }
        System.out.println(sum);
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.*; util.* java public class Main {

    public static void main(String[] args){
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int [] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();
        int sum = 0;
        for (int i = 1; i < n-1; i++){
            int [] new_a = {a[i-1], a[i], a[i+1]};
            Arrays.sort(new_a);
            if (new_a[1] == a[i]){
                sum++;
            }
        }
        System.out.println(sum);
    }
} Main public static void main(String[] args){
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int [] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();
        int sum = 0;
        for (int i = 1; i < n-1; i++){
            int [] new_a = {a[i-1], a[i], a[i+1]};
            Arrays.sort(new_a);
            if (new_a[1] == a[i]){
                sum++;
            }
        }
        System.out.println(sum);
    } main {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int [] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();
        int sum = 0;
        for (int i = 1; i < n-1; i++){
            int [] new_a = {a[i-1], a[i], a[i+1]};
            Arrays.sort(new_a);
            if (new_a[1] == a[i]){
                sum++;
            }
        }
        System.out.println(sum);
    } Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); in new Scanner(new BufferedReader(new InputStreamReader(System.in))) int n = in.nextInt(); n in.nextInt() in.nextInt in int [] a = new int[n]; a new int[n] n for (int i = 0; i < n; i++) a[i] = in.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i a[i] = in.nextInt(); a[i] = in.nextInt() a[i] a i in.nextInt() in.nextInt in int sum = 0; sum 0 for (int i = 1; i < n-1; i++){
            int [] new_a = {a[i-1], a[i], a[i+1]};
            Arrays.sort(new_a);
            if (new_a[1] == a[i]){
                sum++;
            }
        } int i = 1; int i = 1; i 1 i < n-1 i n-1 n 1 i++ i++ i {
            int [] new_a = {a[i-1], a[i], a[i+1]};
            Arrays.sort(new_a);
            if (new_a[1] == a[i]){
                sum++;
            }
        } {
            int [] new_a = {a[i-1], a[i], a[i+1]};
            Arrays.sort(new_a);
            if (new_a[1] == a[i]){
                sum++;
            }
        } int [] new_a = {a[i-1], a[i], a[i+1]}; new_a {a[i-1], a[i], a[i+1]} a[i-1] a i-1 i 1 a[i] a i a[i+1] a i+1 i 1 Arrays.sort(new_a) Arrays.sort Arrays new_a if (new_a[1] == a[i]){
                sum++;
            } new_a[1] == a[i] new_a[1] new_a 1 a[i] a i {
                sum++;
            } sum++ sum System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {

    public static void main(String[] args){
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int [] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();
        int sum = 0;
        for (int i = 1; i < n-1; i++){
            int [] new_a = {a[i-1], a[i], a[i+1]};
            Arrays.sort(new_a);
            if (new_a[1] == a[i]){
                sum++;
            }
        }
        System.out.println(sum);
    }
} public class Main {

    public static void main(String[] args){
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int [] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();
        int sum = 0;
        for (int i = 1; i < n-1; i++){
            int [] new_a = {a[i-1], a[i], a[i+1]};
            Arrays.sort(new_a);
            if (new_a[1] == a[i]){
                sum++;
            }
        }
        System.out.println(sum);
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int [] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();
        int sum = 0;
        for (int i = 1; i < n-1; i++){
            int [] new_a = {a[i-1], a[i], a[i+1]};
            Arrays.sort(new_a);
            if (new_a[1] == a[i]){
                sum++;
            }
        }
        System.out.println(sum);
    }
}