import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int a[] =new int[N];
        
        for(int i=0;i<N;i++){
            a[i] = sc.nextInt();
        }
        
        int num =0;
        
        for(int i=0;i<N-2;i++){
            if(a[i]<a[i+1] && a[i+1]<a[i+2] || a[i]>a[i+1]&&a[i+1]>a[i+2]){
                num +=1;
            }
        }
        System.out.println(num);
        
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int a[] =new int[N];
        
        for(int i=0;i<N;i++){
            a[i] = sc.nextInt();
        }
        
        int num =0;
        
        for(int i=0;i<N-2;i++){
            if(a[i]<a[i+1] && a[i+1]<a[i+2] || a[i]>a[i+1]&&a[i+1]>a[i+2]){
                num +=1;
            }
        }
        System.out.println(num);
        
    }
} Main public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int a[] =new int[N];
        
        for(int i=0;i<N;i++){
            a[i] = sc.nextInt();
        }
        
        int num =0;
        
        for(int i=0;i<N-2;i++){
            if(a[i]<a[i+1] && a[i+1]<a[i+2] || a[i]>a[i+1]&&a[i+1]>a[i+2]){
                num +=1;
            }
        }
        System.out.println(num);
        
    } main {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int a[] =new int[N];
        
        for(int i=0;i<N;i++){
            a[i] = sc.nextInt();
        }
        
        int num =0;
        
        for(int i=0;i<N-2;i++){
            if(a[i]<a[i+1] && a[i+1]<a[i+2] || a[i]>a[i+1]&&a[i+1]>a[i+2]){
                num +=1;
            }
        }
        System.out.println(num);
        
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int a[] =new int[N]; a new int[N] N for(int i=0;i<N;i++){
            a[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            a[i] = sc.nextInt();
        } {
            a[i] = sc.nextInt();
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int num =0; num 0 for(int i=0;i<N-2;i++){
            if(a[i]<a[i+1] && a[i+1]<a[i+2] || a[i]>a[i+1]&&a[i+1]>a[i+2]){
                num +=1;
            }
        } int i=0; int i=0; i 0 i<N-2 i N-2 N 2 i++ i++ i {
            if(a[i]<a[i+1] && a[i+1]<a[i+2] || a[i]>a[i+1]&&a[i+1]>a[i+2]){
                num +=1;
            }
        } {
            if(a[i]<a[i+1] && a[i+1]<a[i+2] || a[i]>a[i+1]&&a[i+1]>a[i+2]){
                num +=1;
            }
        } if(a[i]<a[i+1] && a[i+1]<a[i+2] || a[i]>a[i+1]&&a[i+1]>a[i+2]){
                num +=1;
            } a[i]<a[i+1] && a[i+1]<a[i+2] || a[i]>a[i+1]&&a[i+1]>a[i+2] a[i]<a[i+1] && a[i+1]<a[i+2] a[i]<a[i+1] a[i] a i a[i+1] a i+1 i 1 a[i+1]<a[i+2] a[i+1] a i+1 i 1 a[i+2] a i+2 i 2 a[i]>a[i+1]&&a[i+1]>a[i+2] a[i]>a[i+1] a[i] a i a[i+1] a i+1 i 1 a[i+1]>a[i+2] a[i+1] a i+1 i 1 a[i+2] a i+2 i 2 {
                num +=1;
            } num +=1 num 1 System.out.println(num) System.out.println System.out System System.out num String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int a[] =new int[N];
        
        for(int i=0;i<N;i++){
            a[i] = sc.nextInt();
        }
        
        int num =0;
        
        for(int i=0;i<N-2;i++){
            if(a[i]<a[i+1] && a[i+1]<a[i+2] || a[i]>a[i+1]&&a[i+1]>a[i+2]){
                num +=1;
            }
        }
        System.out.println(num);
        
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int a[] =new int[N];
        
        for(int i=0;i<N;i++){
            a[i] = sc.nextInt();
        }
        
        int num =0;
        
        for(int i=0;i<N-2;i++){
            if(a[i]<a[i+1] && a[i+1]<a[i+2] || a[i]>a[i+1]&&a[i+1]>a[i+2]){
                num +=1;
            }
        }
        System.out.println(num);
        
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int a[] =new int[N];
        
        for(int i=0;i<N;i++){
            a[i] = sc.nextInt();
        }
        
        int num =0;
        
        for(int i=0;i<N-2;i++){
            if(a[i]<a[i+1] && a[i+1]<a[i+2] || a[i]>a[i+1]&&a[i+1]>a[i+2]){
                num +=1;
            }
        }
        System.out.println(num);
        
    }
}
