
import java.util.*;


public class Main {

    private static final int INF = Integer.MAX_VALUE;

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

        List<Integer> list = new ArrayList<>();
        for(int tmp = 0; tmp< n; tmp++){
            int a = sc.nextInt();
            list.add(a);
        }
        int result = 0;

        for(int tmp = 1; tmp<n -1; tmp++){
            int pm = list.get(tmp - 1);
            int p = list.get(tmp);
            int ph = list.get(tmp + 1);

            if((pm < p && p<ph) || (pm >p && p>ph)){

                    result++;
            }
        }

        System.out.println(result);



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

    private static final int INF = Integer.MAX_VALUE;

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

        List<Integer> list = new ArrayList<>();
        for(int tmp = 0; tmp< n; tmp++){
            int a = sc.nextInt();
            list.add(a);
        }
        int result = 0;

        for(int tmp = 1; tmp<n -1; tmp++){
            int pm = list.get(tmp - 1);
            int p = list.get(tmp);
            int ph = list.get(tmp + 1);

            if((pm < p && p<ph) || (pm >p && p>ph)){

                    result++;
            }
        }

        System.out.println(result);



    }
} Main private static final int INF = Integer.MAX_VALUE; INF Integer.MAX_VALUE Integer Integer.MAX_VALUE public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        List<Integer> list = new ArrayList<>();
        for(int tmp = 0; tmp< n; tmp++){
            int a = sc.nextInt();
            list.add(a);
        }
        int result = 0;

        for(int tmp = 1; tmp<n -1; tmp++){
            int pm = list.get(tmp - 1);
            int p = list.get(tmp);
            int ph = list.get(tmp + 1);

            if((pm < p && p<ph) || (pm >p && p>ph)){

                    result++;
            }
        }

        System.out.println(result);



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

        List<Integer> list = new ArrayList<>();
        for(int tmp = 0; tmp< n; tmp++){
            int a = sc.nextInt();
            list.add(a);
        }
        int result = 0;

        for(int tmp = 1; tmp<n -1; tmp++){
            int pm = list.get(tmp - 1);
            int p = list.get(tmp);
            int ph = list.get(tmp + 1);

            if((pm < p && p<ph) || (pm >p && p>ph)){

                    result++;
            }
        }

        System.out.println(result);



    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc List<Integer> list = new ArrayList<>(); list new ArrayList<>() for(int tmp = 0; tmp< n; tmp++){
            int a = sc.nextInt();
            list.add(a);
        } int tmp = 0; int tmp = 0; tmp 0 tmp< n tmp n tmp++ tmp++ tmp {
            int a = sc.nextInt();
            list.add(a);
        } {
            int a = sc.nextInt();
            list.add(a);
        } int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc list.add(a) list.add list a int result = 0; result 0 for(int tmp = 1; tmp<n -1; tmp++){
            int pm = list.get(tmp - 1);
            int p = list.get(tmp);
            int ph = list.get(tmp + 1);

            if((pm < p && p<ph) || (pm >p && p>ph)){

                    result++;
            }
        } int tmp = 1; int tmp = 1; tmp 1 tmp<n -1 tmp n -1 n 1 tmp++ tmp++ tmp {
            int pm = list.get(tmp - 1);
            int p = list.get(tmp);
            int ph = list.get(tmp + 1);

            if((pm < p && p<ph) || (pm >p && p>ph)){

                    result++;
            }
        } {
            int pm = list.get(tmp - 1);
            int p = list.get(tmp);
            int ph = list.get(tmp + 1);

            if((pm < p && p<ph) || (pm >p && p>ph)){

                    result++;
            }
        } int pm = list.get(tmp - 1); pm list.get(tmp - 1) list.get list tmp - 1 tmp 1 int p = list.get(tmp); p list.get(tmp) list.get list tmp int ph = list.get(tmp + 1); ph list.get(tmp + 1) list.get list tmp + 1 tmp 1 if((pm < p && p<ph) || (pm >p && p>ph)){

                    result++;
            } (pm < p && p<ph) || (pm >p && p>ph) (pm < p && p<ph) pm < p pm p p<ph p ph (pm >p && p>ph) pm >p pm p p>ph p ph {

                    result++;
            } result++ result System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {

    private static final int INF = Integer.MAX_VALUE;

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

        List<Integer> list = new ArrayList<>();
        for(int tmp = 0; tmp< n; tmp++){
            int a = sc.nextInt();
            list.add(a);
        }
        int result = 0;

        for(int tmp = 1; tmp<n -1; tmp++){
            int pm = list.get(tmp - 1);
            int p = list.get(tmp);
            int ph = list.get(tmp + 1);

            if((pm < p && p<ph) || (pm >p && p>ph)){

                    result++;
            }
        }

        System.out.println(result);



    }
} public class Main {

    private static final int INF = Integer.MAX_VALUE;

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

        List<Integer> list = new ArrayList<>();
        for(int tmp = 0; tmp< n; tmp++){
            int a = sc.nextInt();
            list.add(a);
        }
        int result = 0;

        for(int tmp = 1; tmp<n -1; tmp++){
            int pm = list.get(tmp - 1);
            int p = list.get(tmp);
            int ph = list.get(tmp + 1);

            if((pm < p && p<ph) || (pm >p && p>ph)){

                    result++;
            }
        }

        System.out.println(result);



    }
} Main

import java.util.*;


public class Main {

    private static final int INF = Integer.MAX_VALUE;

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

        List<Integer> list = new ArrayList<>();
        for(int tmp = 0; tmp< n; tmp++){
            int a = sc.nextInt();
            list.add(a);
        }
        int result = 0;

        for(int tmp = 1; tmp<n -1; tmp++){
            int pm = list.get(tmp - 1);
            int p = list.get(tmp);
            int ph = list.get(tmp + 1);

            if((pm < p && p<ph) || (pm >p && p>ph)){

                    result++;
            }
        }

        System.out.println(result);



    }
}
