import java.util.Scanner;

public class Main {

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

        int arr[]=new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = scanner.nextInt();

        int mainCount=0;

        for (int i = 1; i < n-1; i++) {

            if(arr[i]>arr[i-1] && arr[i]<arr[i+1])
                mainCount++;
            else if(arr[i]<arr[i-1] && arr[i]>arr[i+1])
                mainCount++;
        }

        System.out.println(mainCount);

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

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

        int arr[]=new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = scanner.nextInt();

        int mainCount=0;

        for (int i = 1; i < n-1; i++) {

            if(arr[i]>arr[i-1] && arr[i]<arr[i+1])
                mainCount++;
            else if(arr[i]<arr[i-1] && arr[i]>arr[i+1])
                mainCount++;
        }

        System.out.println(mainCount);

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

        int arr[]=new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = scanner.nextInt();

        int mainCount=0;

        for (int i = 1; i < n-1; i++) {

            if(arr[i]>arr[i-1] && arr[i]<arr[i+1])
                mainCount++;
            else if(arr[i]<arr[i-1] && arr[i]>arr[i+1])
                mainCount++;
        }

        System.out.println(mainCount);

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

        int arr[]=new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = scanner.nextInt();

        int mainCount=0;

        for (int i = 1; i < n-1; i++) {

            if(arr[i]>arr[i-1] && arr[i]<arr[i+1])
                mainCount++;
            else if(arr[i]<arr[i-1] && arr[i]>arr[i+1])
                mainCount++;
        }

        System.out.println(mainCount);

    } Scanner scanner=new Scanner(System.in); scanner new Scanner(System.in) int n=scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int arr[]=new int[n]; arr new int[n] n for (int i = 0; i < n; i++)
            arr[i] = scanner.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i arr[i] = scanner.nextInt(); arr[i] = scanner.nextInt() arr[i] arr i scanner.nextInt() scanner.nextInt scanner int mainCount=0; mainCount 0 for (int i = 1; i < n-1; i++) {

            if(arr[i]>arr[i-1] && arr[i]<arr[i+1])
                mainCount++;
            else if(arr[i]<arr[i-1] && arr[i]>arr[i+1])
                mainCount++;
        } int i = 1; int i = 1; i 1 i < n-1 i n-1 n 1 i++ i++ i {

            if(arr[i]>arr[i-1] && arr[i]<arr[i+1])
                mainCount++;
            else if(arr[i]<arr[i-1] && arr[i]>arr[i+1])
                mainCount++;
        } {

            if(arr[i]>arr[i-1] && arr[i]<arr[i+1])
                mainCount++;
            else if(arr[i]<arr[i-1] && arr[i]>arr[i+1])
                mainCount++;
        } if(arr[i]>arr[i-1] && arr[i]<arr[i+1])
                mainCount++;
            else if(arr[i]<arr[i-1] && arr[i]>arr[i+1])
                mainCount++; arr[i]>arr[i-1] && arr[i]<arr[i+1] arr[i]>arr[i-1] arr[i] arr i arr[i-1] arr i-1 i 1 arr[i]<arr[i+1] arr[i] arr i arr[i+1] arr i+1 i 1 mainCount++ mainCount if(arr[i]<arr[i-1] && arr[i]>arr[i+1])
                mainCount++; arr[i]<arr[i-1] && arr[i]>arr[i+1] arr[i]<arr[i-1] arr[i] arr i arr[i-1] arr i-1 i 1 arr[i]>arr[i+1] arr[i] arr i arr[i+1] arr i+1 i 1 mainCount++ mainCount System.out.println(mainCount) System.out.println System.out System System.out mainCount String[] args args public class Main {

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

        int arr[]=new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = scanner.nextInt();

        int mainCount=0;

        for (int i = 1; i < n-1; i++) {

            if(arr[i]>arr[i-1] && arr[i]<arr[i+1])
                mainCount++;
            else if(arr[i]<arr[i-1] && arr[i]>arr[i+1])
                mainCount++;
        }

        System.out.println(mainCount);

    }
} public class Main {

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

        int arr[]=new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = scanner.nextInt();

        int mainCount=0;

        for (int i = 1; i < n-1; i++) {

            if(arr[i]>arr[i-1] && arr[i]<arr[i+1])
                mainCount++;
            else if(arr[i]<arr[i-1] && arr[i]>arr[i+1])
                mainCount++;
        }

        System.out.println(mainCount);

    }
} Main
import java.util.Scanner;

public class Main {

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

        int arr[]=new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = scanner.nextInt();

        int mainCount=0;

        for (int i = 1; i < n-1; i++) {

            if(arr[i]>arr[i-1] && arr[i]<arr[i+1])
                mainCount++;
            else if(arr[i]<arr[i-1] && arr[i]>arr[i+1])
                mainCount++;
        }

        System.out.println(mainCount);

    }
}
