import java.util.ArrayList;
import java.util.Scanner;

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

        int n = sc.nextInt();

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

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


        int cnt = 0;

        for(int i=0; i<arrayList.size()-2; i++){

            int first = arrayList.get(i);
            int mid = arrayList.get(i+1);
            int last = arrayList.get(i+2);

            int max = Math.max(first, last);
            int min = Math.min(first, last);

            if(min < mid && mid < max){
                cnt++;
            }
        }

        System.out.println(cnt);

    }
} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

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

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


        int cnt = 0;

        for(int i=0; i<arrayList.size()-2; i++){

            int first = arrayList.get(i);
            int mid = arrayList.get(i+1);
            int last = arrayList.get(i+2);

            int max = Math.max(first, last);
            int min = Math.min(first, last);

            if(min < mid && mid < max){
                cnt++;
            }
        }

        System.out.println(cnt);

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

        int n = sc.nextInt();

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

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


        int cnt = 0;

        for(int i=0; i<arrayList.size()-2; i++){

            int first = arrayList.get(i);
            int mid = arrayList.get(i+1);
            int last = arrayList.get(i+2);

            int max = Math.max(first, last);
            int min = Math.min(first, last);

            if(min < mid && mid < max){
                cnt++;
            }
        }

        System.out.println(cnt);

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

        int n = sc.nextInt();

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

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


        int cnt = 0;

        for(int i=0; i<arrayList.size()-2; i++){

            int first = arrayList.get(i);
            int mid = arrayList.get(i+1);
            int last = arrayList.get(i+2);

            int max = Math.max(first, last);
            int min = Math.min(first, last);

            if(min < mid && mid < max){
                cnt++;
            }
        }

        System.out.println(cnt);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc ArrayList<Integer> arrayList = new ArrayList<Integer>(); arrayList new ArrayList<Integer>() for(int i=0; i<n; i++){
            int p = sc.nextInt();
            arrayList.add(p);
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            int p = sc.nextInt();
            arrayList.add(p);
        } {
            int p = sc.nextInt();
            arrayList.add(p);
        } int p = sc.nextInt(); p sc.nextInt() sc.nextInt sc arrayList.add(p) arrayList.add arrayList p int cnt = 0; cnt 0 for(int i=0; i<arrayList.size()-2; i++){

            int first = arrayList.get(i);
            int mid = arrayList.get(i+1);
            int last = arrayList.get(i+2);

            int max = Math.max(first, last);
            int min = Math.min(first, last);

            if(min < mid && mid < max){
                cnt++;
            }
        } int i=0; int i=0; i 0 i<arrayList.size()-2 i arrayList.size()-2 arrayList.size() arrayList.size arrayList 2 i++ i++ i {

            int first = arrayList.get(i);
            int mid = arrayList.get(i+1);
            int last = arrayList.get(i+2);

            int max = Math.max(first, last);
            int min = Math.min(first, last);

            if(min < mid && mid < max){
                cnt++;
            }
        } {

            int first = arrayList.get(i);
            int mid = arrayList.get(i+1);
            int last = arrayList.get(i+2);

            int max = Math.max(first, last);
            int min = Math.min(first, last);

            if(min < mid && mid < max){
                cnt++;
            }
        } int first = arrayList.get(i); first arrayList.get(i) arrayList.get arrayList i int mid = arrayList.get(i+1); mid arrayList.get(i+1) arrayList.get arrayList i+1 i 1 int last = arrayList.get(i+2); last arrayList.get(i+2) arrayList.get arrayList i+2 i 2 int max = Math.max(first, last); max Math.max(first, last) Math.max Math first last int min = Math.min(first, last); min Math.min(first, last) Math.min Math first last if(min < mid && mid < max){
                cnt++;
            } min < mid && mid < max min < mid min mid mid < max mid max {
                cnt++;
            } cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

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

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


        int cnt = 0;

        for(int i=0; i<arrayList.size()-2; i++){

            int first = arrayList.get(i);
            int mid = arrayList.get(i+1);
            int last = arrayList.get(i+2);

            int max = Math.max(first, last);
            int min = Math.min(first, last);

            if(min < mid && mid < max){
                cnt++;
            }
        }

        System.out.println(cnt);

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

        int n = sc.nextInt();

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

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


        int cnt = 0;

        for(int i=0; i<arrayList.size()-2; i++){

            int first = arrayList.get(i);
            int mid = arrayList.get(i+1);
            int last = arrayList.get(i+2);

            int max = Math.max(first, last);
            int min = Math.min(first, last);

            if(min < mid && mid < max){
                cnt++;
            }
        }

        System.out.println(cnt);

    }
} Main
import java.util.ArrayList;
import java.util.Scanner;

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

        int n = sc.nextInt();

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

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


        int cnt = 0;

        for(int i=0; i<arrayList.size()-2; i++){

            int first = arrayList.get(i);
            int mid = arrayList.get(i+1);
            int last = arrayList.get(i+2);

            int max = Math.max(first, last);
            int min = Math.min(first, last);

            if(min < mid && mid < max){
                cnt++;
            }
        }

        System.out.println(cnt);

    }
}