import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] list = new int[n];
        
        for (int i = 0; i < n; i++) {
            list[i]= sc.nextInt();
        }
        int c = 0;
        for (int i = 1; i < n-1; i++) {
            if( (list[i] > list[i-1] && list[i] < list[i+1]) ||
                    (list[i] < list[i-1] && list[i] > list[i+1]) ) {
                c++;
            }
        }
        

        System.out.println(c);   
        }
} 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();
        int[] list = new int[n];
        
        for (int i = 0; i < n; i++) {
            list[i]= sc.nextInt();
        }
        int c = 0;
        for (int i = 1; i < n-1; i++) {
            if( (list[i] > list[i-1] && list[i] < list[i+1]) ||
                    (list[i] < list[i-1] && list[i] > list[i+1]) ) {
                c++;
            }
        }
        

        System.out.println(c);   
        }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] list = new int[n];
        
        for (int i = 0; i < n; i++) {
            list[i]= sc.nextInt();
        }
        int c = 0;
        for (int i = 1; i < n-1; i++) {
            if( (list[i] > list[i-1] && list[i] < list[i+1]) ||
                    (list[i] < list[i-1] && list[i] > list[i+1]) ) {
                c++;
            }
        }
        

        System.out.println(c);   
        } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] list = new int[n];
        
        for (int i = 0; i < n; i++) {
            list[i]= sc.nextInt();
        }
        int c = 0;
        for (int i = 1; i < n-1; i++) {
            if( (list[i] > list[i-1] && list[i] < list[i+1]) ||
                    (list[i] < list[i-1] && list[i] > list[i+1]) ) {
                c++;
            }
        }
        

        System.out.println(c);   
        } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] list = new int[n]; list new int[n] n for (int i = 0; i < n; i++) {
            list[i]= sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            list[i]= sc.nextInt();
        } {
            list[i]= sc.nextInt();
        } list[i]= sc.nextInt() list[i] list i sc.nextInt() sc.nextInt sc int c = 0; c 0 for (int i = 1; i < n-1; i++) {
            if( (list[i] > list[i-1] && list[i] < list[i+1]) ||
                    (list[i] < list[i-1] && list[i] > list[i+1]) ) {
                c++;
            }
        } int i = 1; int i = 1; i 1 i < n-1 i n-1 n 1 i++ i++ i {
            if( (list[i] > list[i-1] && list[i] < list[i+1]) ||
                    (list[i] < list[i-1] && list[i] > list[i+1]) ) {
                c++;
            }
        } {
            if( (list[i] > list[i-1] && list[i] < list[i+1]) ||
                    (list[i] < list[i-1] && list[i] > list[i+1]) ) {
                c++;
            }
        } if( (list[i] > list[i-1] && list[i] < list[i+1]) ||
                    (list[i] < list[i-1] && list[i] > list[i+1]) ) {
                c++;
            } (list[i] > list[i-1] && list[i] < list[i+1]) ||
                    (list[i] < list[i-1] && list[i] > list[i+1]) (list[i] > list[i-1] && list[i] < list[i+1]) list[i] > list[i-1] list[i] list i list[i-1] list i-1 i 1 list[i] < list[i+1] list[i] list i list[i+1] list i+1 i 1 (list[i] < list[i-1] && list[i] > list[i+1]) list[i] < list[i-1] list[i] list i list[i-1] list i-1 i 1 list[i] > list[i+1] list[i] list i list[i+1] list i+1 i 1 {
                c++;
            } c++ c System.out.println(c) System.out.println System.out System System.out c String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] list = new int[n];
        
        for (int i = 0; i < n; i++) {
            list[i]= sc.nextInt();
        }
        int c = 0;
        for (int i = 1; i < n-1; i++) {
            if( (list[i] > list[i-1] && list[i] < list[i+1]) ||
                    (list[i] < list[i-1] && list[i] > list[i+1]) ) {
                c++;
            }
        }
        

        System.out.println(c);   
        }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] list = new int[n];
        
        for (int i = 0; i < n; i++) {
            list[i]= sc.nextInt();
        }
        int c = 0;
        for (int i = 1; i < n-1; i++) {
            if( (list[i] > list[i-1] && list[i] < list[i+1]) ||
                    (list[i] < list[i-1] && list[i] > list[i+1]) ) {
                c++;
            }
        }
        

        System.out.println(c);   
        }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] list = new int[n];
        
        for (int i = 0; i < n; i++) {
            list[i]= sc.nextInt();
        }
        int c = 0;
        for (int i = 1; i < n-1; i++) {
            if( (list[i] > list[i-1] && list[i] < list[i+1]) ||
                    (list[i] < list[i-1] && list[i] > list[i+1]) ) {
                c++;
            }
        }
        

        System.out.println(c);   
        }
}
