import java.util.*;

public class Main {


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

        int n  = sc.nextInt();

        ArrayList<Integer> p = new ArrayList<>();

        for(int i = 0; i < n; i++){
            p.add(sc.nextInt());
        }

        ArrayList<Integer> calcList = new ArrayList<>();
        int ans = 0;
        for(int i = 1; i < n - 1; i++){
            calcList.addAll(p.subList(i - 1, i + 2));
            Collections.sort(calcList);
            if(calcList.get(1).equals(p.get(i))){
                ans++;
            }

            calcList.clear();
        }

        System.out.println(ans);

        return;
    }
} import java.util.*; util.* java public class Main {


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

        int n  = sc.nextInt();

        ArrayList<Integer> p = new ArrayList<>();

        for(int i = 0; i < n; i++){
            p.add(sc.nextInt());
        }

        ArrayList<Integer> calcList = new ArrayList<>();
        int ans = 0;
        for(int i = 1; i < n - 1; i++){
            calcList.addAll(p.subList(i - 1, i + 2));
            Collections.sort(calcList);
            if(calcList.get(1).equals(p.get(i))){
                ans++;
            }

            calcList.clear();
        }

        System.out.println(ans);

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

        int n  = sc.nextInt();

        ArrayList<Integer> p = new ArrayList<>();

        for(int i = 0; i < n; i++){
            p.add(sc.nextInt());
        }

        ArrayList<Integer> calcList = new ArrayList<>();
        int ans = 0;
        for(int i = 1; i < n - 1; i++){
            calcList.addAll(p.subList(i - 1, i + 2));
            Collections.sort(calcList);
            if(calcList.get(1).equals(p.get(i))){
                ans++;
            }

            calcList.clear();
        }

        System.out.println(ans);

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

        int n  = sc.nextInt();

        ArrayList<Integer> p = new ArrayList<>();

        for(int i = 0; i < n; i++){
            p.add(sc.nextInt());
        }

        ArrayList<Integer> calcList = new ArrayList<>();
        int ans = 0;
        for(int i = 1; i < n - 1; i++){
            calcList.addAll(p.subList(i - 1, i + 2));
            Collections.sort(calcList);
            if(calcList.get(1).equals(p.get(i))){
                ans++;
            }

            calcList.clear();
        }

        System.out.println(ans);

        return;
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n  = sc.nextInt(); n sc.nextInt() sc.nextInt sc ArrayList<Integer> p = new ArrayList<>(); p new ArrayList<>() for(int i = 0; i < n; i++){
            p.add(sc.nextInt());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            p.add(sc.nextInt());
        } {
            p.add(sc.nextInt());
        } p.add(sc.nextInt()) p.add p sc.nextInt() sc.nextInt sc ArrayList<Integer> calcList = new ArrayList<>(); calcList new ArrayList<>() int ans = 0; ans 0 for(int i = 1; i < n - 1; i++){
            calcList.addAll(p.subList(i - 1, i + 2));
            Collections.sort(calcList);
            if(calcList.get(1).equals(p.get(i))){
                ans++;
            }

            calcList.clear();
        } int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i {
            calcList.addAll(p.subList(i - 1, i + 2));
            Collections.sort(calcList);
            if(calcList.get(1).equals(p.get(i))){
                ans++;
            }

            calcList.clear();
        } {
            calcList.addAll(p.subList(i - 1, i + 2));
            Collections.sort(calcList);
            if(calcList.get(1).equals(p.get(i))){
                ans++;
            }

            calcList.clear();
        } calcList.addAll(p.subList(i - 1, i + 2)) calcList.addAll calcList p.subList(i - 1, i + 2) p.subList p i - 1 i 1 i + 2 i 2 Collections.sort(calcList) Collections.sort Collections calcList if(calcList.get(1).equals(p.get(i))){
                ans++;
            } calcList.get(1).equals(p.get(i)) calcList.get(1).equals calcList.get(1) calcList.get calcList 1 p.get(i) p.get p i {
                ans++;
            } ans++ ans calcList.clear() calcList.clear calcList System.out.println(ans) System.out.println System.out System System.out ans return; String[] args args public class Main {


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

        int n  = sc.nextInt();

        ArrayList<Integer> p = new ArrayList<>();

        for(int i = 0; i < n; i++){
            p.add(sc.nextInt());
        }

        ArrayList<Integer> calcList = new ArrayList<>();
        int ans = 0;
        for(int i = 1; i < n - 1; i++){
            calcList.addAll(p.subList(i - 1, i + 2));
            Collections.sort(calcList);
            if(calcList.get(1).equals(p.get(i))){
                ans++;
            }

            calcList.clear();
        }

        System.out.println(ans);

        return;
    }
} public class Main {


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

        int n  = sc.nextInt();

        ArrayList<Integer> p = new ArrayList<>();

        for(int i = 0; i < n; i++){
            p.add(sc.nextInt());
        }

        ArrayList<Integer> calcList = new ArrayList<>();
        int ans = 0;
        for(int i = 1; i < n - 1; i++){
            calcList.addAll(p.subList(i - 1, i + 2));
            Collections.sort(calcList);
            if(calcList.get(1).equals(p.get(i))){
                ans++;
            }

            calcList.clear();
        }

        System.out.println(ans);

        return;
    }
} Main
import java.util.*;

public class Main {


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

        int n  = sc.nextInt();

        ArrayList<Integer> p = new ArrayList<>();

        for(int i = 0; i < n; i++){
            p.add(sc.nextInt());
        }

        ArrayList<Integer> calcList = new ArrayList<>();
        int ans = 0;
        for(int i = 1; i < n - 1; i++){
            calcList.addAll(p.subList(i - 1, i + 2));
            Collections.sort(calcList);
            if(calcList.get(1).equals(p.get(i))){
                ans++;
            }

            calcList.clear();
        }

        System.out.println(ans);

        return;
    }
}
