import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int len = sc.nextInt();
        List<Integer> num = new ArrayList<>();
        for(int i = 0;i < len;i++){
            num.add(sc.nextInt());
        }
        //System.out.println(num);
        //System.out.println(len);
        int counter = 0;
        for(int i = 0;i < len-2;i++){
            int one = num.get(0);
            //System.out.println(one);
            int two = num.get(1);
            int three = num.get(2);
            if((one < two) && (two < three)){
                counter++;
            }else if((one > two) && (two > three)){
                counter++;
            }
            num.remove(0);
        }
        System.out.println(counter);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int len = sc.nextInt();
        List<Integer> num = new ArrayList<>();
        for(int i = 0;i < len;i++){
            num.add(sc.nextInt());
        }
        //System.out.println(num);
        //System.out.println(len);
        int counter = 0;
        for(int i = 0;i < len-2;i++){
            int one = num.get(0);
            //System.out.println(one);
            int two = num.get(1);
            int three = num.get(2);
            if((one < two) && (two < three)){
                counter++;
            }else if((one > two) && (two > three)){
                counter++;
            }
            num.remove(0);
        }
        System.out.println(counter);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int len = sc.nextInt();
        List<Integer> num = new ArrayList<>();
        for(int i = 0;i < len;i++){
            num.add(sc.nextInt());
        }
        //System.out.println(num);
        //System.out.println(len);
        int counter = 0;
        for(int i = 0;i < len-2;i++){
            int one = num.get(0);
            //System.out.println(one);
            int two = num.get(1);
            int three = num.get(2);
            if((one < two) && (two < three)){
                counter++;
            }else if((one > two) && (two > three)){
                counter++;
            }
            num.remove(0);
        }
        System.out.println(counter);
    } main {
        Scanner sc = new Scanner(System.in);
        int len = sc.nextInt();
        List<Integer> num = new ArrayList<>();
        for(int i = 0;i < len;i++){
            num.add(sc.nextInt());
        }
        //System.out.println(num);
        //System.out.println(len);
        int counter = 0;
        for(int i = 0;i < len-2;i++){
            int one = num.get(0);
            //System.out.println(one);
            int two = num.get(1);
            int three = num.get(2);
            if((one < two) && (two < three)){
                counter++;
            }else if((one > two) && (two > three)){
                counter++;
            }
            num.remove(0);
        }
        System.out.println(counter);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int len = sc.nextInt(); len sc.nextInt() sc.nextInt sc List<Integer> num = new ArrayList<>(); num new ArrayList<>() for(int i = 0;i < len;i++){
            num.add(sc.nextInt());
        } int i = 0; int i = 0; i 0 i < len i len i++ i++ i {
            num.add(sc.nextInt());
        } {
            num.add(sc.nextInt());
        } num.add(sc.nextInt()) num.add num sc.nextInt() sc.nextInt sc int counter = 0; counter 0 for(int i = 0;i < len-2;i++){
            int one = num.get(0);
            //System.out.println(one);
            int two = num.get(1);
            int three = num.get(2);
            if((one < two) && (two < three)){
                counter++;
            }else if((one > two) && (two > three)){
                counter++;
            }
            num.remove(0);
        } int i = 0; int i = 0; i 0 i < len-2 i len-2 len 2 i++ i++ i {
            int one = num.get(0);
            //System.out.println(one);
            int two = num.get(1);
            int three = num.get(2);
            if((one < two) && (two < three)){
                counter++;
            }else if((one > two) && (two > three)){
                counter++;
            }
            num.remove(0);
        } {
            int one = num.get(0);
            //System.out.println(one);
            int two = num.get(1);
            int three = num.get(2);
            if((one < two) && (two < three)){
                counter++;
            }else if((one > two) && (two > three)){
                counter++;
            }
            num.remove(0);
        } int one = num.get(0); one num.get(0) num.get num 0 int two = num.get(1); two num.get(1) num.get num 1 int three = num.get(2); three num.get(2) num.get num 2 if((one < two) && (two < three)){
                counter++;
            }else if((one > two) && (two > three)){
                counter++;
            } (one < two) && (two < three) (one < two) one two (two < three) two three {
                counter++;
            } counter++ counter if((one > two) && (two > three)){
                counter++;
            } (one > two) && (two > three) (one > two) one two (two > three) two three {
                counter++;
            } counter++ counter num.remove(0) num.remove num 0 System.out.println(counter) System.out.println System.out System System.out counter String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int len = sc.nextInt();
        List<Integer> num = new ArrayList<>();
        for(int i = 0;i < len;i++){
            num.add(sc.nextInt());
        }
        //System.out.println(num);
        //System.out.println(len);
        int counter = 0;
        for(int i = 0;i < len-2;i++){
            int one = num.get(0);
            //System.out.println(one);
            int two = num.get(1);
            int three = num.get(2);
            if((one < two) && (two < three)){
                counter++;
            }else if((one > two) && (two > three)){
                counter++;
            }
            num.remove(0);
        }
        System.out.println(counter);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int len = sc.nextInt();
        List<Integer> num = new ArrayList<>();
        for(int i = 0;i < len;i++){
            num.add(sc.nextInt());
        }
        //System.out.println(num);
        //System.out.println(len);
        int counter = 0;
        for(int i = 0;i < len-2;i++){
            int one = num.get(0);
            //System.out.println(one);
            int two = num.get(1);
            int three = num.get(2);
            if((one < two) && (two < three)){
                counter++;
            }else if((one > two) && (two > three)){
                counter++;
            }
            num.remove(0);
        }
        System.out.println(counter);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int len = sc.nextInt();
        List<Integer> num = new ArrayList<>();
        for(int i = 0;i < len;i++){
            num.add(sc.nextInt());
        }
        //System.out.println(num);
        //System.out.println(len);
        int counter = 0;
        for(int i = 0;i < len-2;i++){
            int one = num.get(0);
            //System.out.println(one);
            int two = num.get(1);
            int three = num.get(2);
            if((one < two) && (two < three)){
                counter++;
            }else if((one > two) && (two > three)){
                counter++;
            }
            num.remove(0);
        }
        System.out.println(counter);
    }
}
