import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int [] A = new int [N+1];
        for(int i = 1; i<N+1; i++){
            A[i] = scanner.nextInt();
        }
        scanner.close();
        
        int count = 0;
        for(int j = 2; j<N; j++){
            if((A[j-1]<A[j] && A[j]<A[j+1]) || (A[j-1]>A[j] && A[j]>A[j+1])){
            count++;
            }
        }
        
        System.out.println(count);
        
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int [] A = new int [N+1];
        for(int i = 1; i<N+1; i++){
            A[i] = scanner.nextInt();
        }
        scanner.close();
        
        int count = 0;
        for(int j = 2; j<N; j++){
            if((A[j-1]<A[j] && A[j]<A[j+1]) || (A[j-1]>A[j] && A[j]>A[j+1])){
            count++;
            }
        }
        
        System.out.println(count);
        
    }
} Main public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int [] A = new int [N+1];
        for(int i = 1; i<N+1; i++){
            A[i] = scanner.nextInt();
        }
        scanner.close();
        
        int count = 0;
        for(int j = 2; j<N; j++){
            if((A[j-1]<A[j] && A[j]<A[j+1]) || (A[j-1]>A[j] && A[j]>A[j+1])){
            count++;
            }
        }
        
        System.out.println(count);
        
    } main {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int [] A = new int [N+1];
        for(int i = 1; i<N+1; i++){
            A[i] = scanner.nextInt();
        }
        scanner.close();
        
        int count = 0;
        for(int j = 2; j<N; j++){
            if((A[j-1]<A[j] && A[j]<A[j+1]) || (A[j-1]>A[j] && A[j]>A[j+1])){
            count++;
            }
        }
        
        System.out.println(count);
        
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int [] A = new int [N+1]; A new int [N+1] N+1 N 1 for(int i = 1; i<N+1; i++){
            A[i] = scanner.nextInt();
        } int i = 1; int i = 1; i 1 i<N+1 i N+1 N 1 i++ i++ i {
            A[i] = scanner.nextInt();
        } {
            A[i] = scanner.nextInt();
        } A[i] = scanner.nextInt() A[i] A i scanner.nextInt() scanner.nextInt scanner scanner.close() scanner.close scanner int count = 0; count 0 for(int j = 2; j<N; j++){
            if((A[j-1]<A[j] && A[j]<A[j+1]) || (A[j-1]>A[j] && A[j]>A[j+1])){
            count++;
            }
        } int j = 2; int j = 2; j 2 j<N j N j++ j++ j {
            if((A[j-1]<A[j] && A[j]<A[j+1]) || (A[j-1]>A[j] && A[j]>A[j+1])){
            count++;
            }
        } {
            if((A[j-1]<A[j] && A[j]<A[j+1]) || (A[j-1]>A[j] && A[j]>A[j+1])){
            count++;
            }
        } if((A[j-1]<A[j] && A[j]<A[j+1]) || (A[j-1]>A[j] && A[j]>A[j+1])){
            count++;
            } (A[j-1]<A[j] && A[j]<A[j+1]) || (A[j-1]>A[j] && A[j]>A[j+1]) (A[j-1]<A[j] && A[j]<A[j+1]) A[j-1]<A[j] A[j-1] A j-1 j 1 A[j] A j A[j]<A[j+1] A[j] A j A[j+1] A j+1 j 1 (A[j-1]>A[j] && A[j]>A[j+1]) A[j-1]>A[j] A[j-1] A j-1 j 1 A[j] A j A[j]>A[j+1] A[j] A j A[j+1] A j+1 j 1 {
            count++;
            } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int [] A = new int [N+1];
        for(int i = 1; i<N+1; i++){
            A[i] = scanner.nextInt();
        }
        scanner.close();
        
        int count = 0;
        for(int j = 2; j<N; j++){
            if((A[j-1]<A[j] && A[j]<A[j+1]) || (A[j-1]>A[j] && A[j]>A[j+1])){
            count++;
            }
        }
        
        System.out.println(count);
        
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int [] A = new int [N+1];
        for(int i = 1; i<N+1; i++){
            A[i] = scanner.nextInt();
        }
        scanner.close();
        
        int count = 0;
        for(int j = 2; j<N; j++){
            if((A[j-1]<A[j] && A[j]<A[j+1]) || (A[j-1]>A[j] && A[j]>A[j+1])){
            count++;
            }
        }
        
        System.out.println(count);
        
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int [] A = new int [N+1];
        for(int i = 1; i<N+1; i++){
            A[i] = scanner.nextInt();
        }
        scanner.close();
        
        int count = 0;
        for(int j = 2; j<N; j++){
            if((A[j-1]<A[j] && A[j]<A[j+1]) || (A[j-1]>A[j] && A[j]>A[j+1])){
            count++;
            }
        }
        
        System.out.println(count);
        
    }
}
