import java.util.*;
import java.io.*;
import java.lang.*;

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

        int n = sc.nextInt();

        ArrayList<Integer> arr = new ArrayList<>();
        int ans = 0;
        for (int i = 0; i<n; i++){
            int a = sc.nextInt();
            arr.add(a);
        }
        for (int i = 1; i<(n-1); i++){
            if (arr.get(i) > arr.get(i-1) && (arr.get(i) < arr.get(i+1))){
                ans++;
            }
            else if (arr.get(i) < arr.get(i-1) && (arr.get(i) > arr.get(i+1))){
                ans++;
            }
        }
        System.out.println(ans);
    }
} import java.util.*; util.* java import java.io.*; io.* java import java.lang.*; lang.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        ArrayList<Integer> arr = new ArrayList<>();
        int ans = 0;
        for (int i = 0; i<n; i++){
            int a = sc.nextInt();
            arr.add(a);
        }
        for (int i = 1; i<(n-1); i++){
            if (arr.get(i) > arr.get(i-1) && (arr.get(i) < arr.get(i+1))){
                ans++;
            }
            else if (arr.get(i) < arr.get(i-1) && (arr.get(i) > arr.get(i+1))){
                ans++;
            }
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        ArrayList<Integer> arr = new ArrayList<>();
        int ans = 0;
        for (int i = 0; i<n; i++){
            int a = sc.nextInt();
            arr.add(a);
        }
        for (int i = 1; i<(n-1); i++){
            if (arr.get(i) > arr.get(i-1) && (arr.get(i) < arr.get(i+1))){
                ans++;
            }
            else if (arr.get(i) < arr.get(i-1) && (arr.get(i) > arr.get(i+1))){
                ans++;
            }
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        ArrayList<Integer> arr = new ArrayList<>();
        int ans = 0;
        for (int i = 0; i<n; i++){
            int a = sc.nextInt();
            arr.add(a);
        }
        for (int i = 1; i<(n-1); i++){
            if (arr.get(i) > arr.get(i-1) && (arr.get(i) < arr.get(i+1))){
                ans++;
            }
            else if (arr.get(i) < arr.get(i-1) && (arr.get(i) > arr.get(i+1))){
                ans++;
            }
        }
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc ArrayList<Integer> arr = new ArrayList<>(); arr new ArrayList<>() int ans = 0; ans 0 for (int i = 0; i<n; i++){
            int a = sc.nextInt();
            arr.add(a);
        } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
            int a = sc.nextInt();
            arr.add(a);
        } {
            int a = sc.nextInt();
            arr.add(a);
        } int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc arr.add(a) arr.add arr a for (int i = 1; i<(n-1); i++){
            if (arr.get(i) > arr.get(i-1) && (arr.get(i) < arr.get(i+1))){
                ans++;
            }
            else if (arr.get(i) < arr.get(i-1) && (arr.get(i) > arr.get(i+1))){
                ans++;
            }
        } int i = 1; int i = 1; i 1 i<(n-1) i (n-1) n 1 i++ i++ i {
            if (arr.get(i) > arr.get(i-1) && (arr.get(i) < arr.get(i+1))){
                ans++;
            }
            else if (arr.get(i) < arr.get(i-1) && (arr.get(i) > arr.get(i+1))){
                ans++;
            }
        } {
            if (arr.get(i) > arr.get(i-1) && (arr.get(i) < arr.get(i+1))){
                ans++;
            }
            else if (arr.get(i) < arr.get(i-1) && (arr.get(i) > arr.get(i+1))){
                ans++;
            }
        } if (arr.get(i) > arr.get(i-1) && (arr.get(i) < arr.get(i+1))){
                ans++;
            }
            else if (arr.get(i) < arr.get(i-1) && (arr.get(i) > arr.get(i+1))){
                ans++;
            } arr.get(i) > arr.get(i-1) && (arr.get(i) < arr.get(i+1)) arr.get(i) > arr.get(i-1) arr.get(i) arr.get arr i arr.get(i-1) arr.get arr i-1 i 1 (arr.get(i) < arr.get(i+1)) arr.get(i) arr.get arr i arr.get(i+1) arr.get arr i+1 i 1 {
                ans++;
            } ans++ ans if (arr.get(i) < arr.get(i-1) && (arr.get(i) > arr.get(i+1))){
                ans++;
            } arr.get(i) < arr.get(i-1) && (arr.get(i) > arr.get(i+1)) arr.get(i) < arr.get(i-1) arr.get(i) arr.get arr i arr.get(i-1) arr.get arr i-1 i 1 (arr.get(i) > arr.get(i+1)) arr.get(i) arr.get arr i arr.get(i+1) arr.get arr i+1 i 1 {
                ans++;
            } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        ArrayList<Integer> arr = new ArrayList<>();
        int ans = 0;
        for (int i = 0; i<n; i++){
            int a = sc.nextInt();
            arr.add(a);
        }
        for (int i = 1; i<(n-1); i++){
            if (arr.get(i) > arr.get(i-1) && (arr.get(i) < arr.get(i+1))){
                ans++;
            }
            else if (arr.get(i) < arr.get(i-1) && (arr.get(i) > arr.get(i+1))){
                ans++;
            }
        }
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        ArrayList<Integer> arr = new ArrayList<>();
        int ans = 0;
        for (int i = 0; i<n; i++){
            int a = sc.nextInt();
            arr.add(a);
        }
        for (int i = 1; i<(n-1); i++){
            if (arr.get(i) > arr.get(i-1) && (arr.get(i) < arr.get(i+1))){
                ans++;
            }
            else if (arr.get(i) < arr.get(i-1) && (arr.get(i) > arr.get(i+1))){
                ans++;
            }
        }
        System.out.println(ans);
    }
} Main
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int n = sc.nextInt();

        ArrayList<Integer> arr = new ArrayList<>();
        int ans = 0;
        for (int i = 0; i<n; i++){
            int a = sc.nextInt();
            arr.add(a);
        }
        for (int i = 1; i<(n-1); i++){
            if (arr.get(i) > arr.get(i-1) && (arr.get(i) < arr.get(i+1))){
                ans++;
            }
            else if (arr.get(i) < arr.get(i-1) && (arr.get(i) > arr.get(i+1))){
                ans++;
            }
        }
        System.out.println(ans);
    }
}