import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int count = 0;
        int num[] = new int[n];
        
        for(int i = 0; i < n; i++){
            num[i] = stdIn.nextInt();
        }
        
        for(int i = 1; i < n - 1; i++){
            if(num[i - 1] > num[i]){
                if(num[i] > num[i + 1]){
                    count++;
                }
            }else{
                if(num[i] < num[i + 1]){
                    count++;
                }
            }
        }
        
        System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int count = 0;
        int num[] = new int[n];
        
        for(int i = 0; i < n; i++){
            num[i] = stdIn.nextInt();
        }
        
        for(int i = 1; i < n - 1; i++){
            if(num[i - 1] > num[i]){
                if(num[i] > num[i + 1]){
                    count++;
                }
            }else{
                if(num[i] < num[i + 1]){
                    count++;
                }
            }
        }
        
        System.out.println(count);
    }
} Main public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int count = 0;
        int num[] = new int[n];
        
        for(int i = 0; i < n; i++){
            num[i] = stdIn.nextInt();
        }
        
        for(int i = 1; i < n - 1; i++){
            if(num[i - 1] > num[i]){
                if(num[i] > num[i + 1]){
                    count++;
                }
            }else{
                if(num[i] < num[i + 1]){
                    count++;
                }
            }
        }
        
        System.out.println(count);
    } main {
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int count = 0;
        int num[] = new int[n];
        
        for(int i = 0; i < n; i++){
            num[i] = stdIn.nextInt();
        }
        
        for(int i = 1; i < n - 1; i++){
            if(num[i - 1] > num[i]){
                if(num[i] > num[i + 1]){
                    count++;
                }
            }else{
                if(num[i] < num[i + 1]){
                    count++;
                }
            }
        }
        
        System.out.println(count);
    } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int count = 0; count 0 int num[] = new int[n]; num new int[n] n for(int i = 0; i < n; i++){
            num[i] = stdIn.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            num[i] = stdIn.nextInt();
        } {
            num[i] = stdIn.nextInt();
        } num[i] = stdIn.nextInt() num[i] num i stdIn.nextInt() stdIn.nextInt stdIn for(int i = 1; i < n - 1; i++){
            if(num[i - 1] > num[i]){
                if(num[i] > num[i + 1]){
                    count++;
                }
            }else{
                if(num[i] < num[i + 1]){
                    count++;
                }
            }
        } int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i {
            if(num[i - 1] > num[i]){
                if(num[i] > num[i + 1]){
                    count++;
                }
            }else{
                if(num[i] < num[i + 1]){
                    count++;
                }
            }
        } {
            if(num[i - 1] > num[i]){
                if(num[i] > num[i + 1]){
                    count++;
                }
            }else{
                if(num[i] < num[i + 1]){
                    count++;
                }
            }
        } if(num[i - 1] > num[i]){
                if(num[i] > num[i + 1]){
                    count++;
                }
            }else{
                if(num[i] < num[i + 1]){
                    count++;
                }
            } num[i - 1] > num[i] num[i - 1] num i - 1 i 1 num[i] num i {
                if(num[i] > num[i + 1]){
                    count++;
                }
            } if(num[i] > num[i + 1]){
                    count++;
                } num[i] > num[i + 1] num[i] num i num[i + 1] num i + 1 i 1 {
                    count++;
                } count++ count {
                if(num[i] < num[i + 1]){
                    count++;
                }
            } if(num[i] < num[i + 1]){
                    count++;
                } num[i] < num[i + 1] num[i] num i num[i + 1] num i + 1 i 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[]){
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int count = 0;
        int num[] = new int[n];
        
        for(int i = 0; i < n; i++){
            num[i] = stdIn.nextInt();
        }
        
        for(int i = 1; i < n - 1; i++){
            if(num[i - 1] > num[i]){
                if(num[i] > num[i + 1]){
                    count++;
                }
            }else{
                if(num[i] < num[i + 1]){
                    count++;
                }
            }
        }
        
        System.out.println(count);
    }
} public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int count = 0;
        int num[] = new int[n];
        
        for(int i = 0; i < n; i++){
            num[i] = stdIn.nextInt();
        }
        
        for(int i = 1; i < n - 1; i++){
            if(num[i - 1] > num[i]){
                if(num[i] > num[i + 1]){
                    count++;
                }
            }else{
                if(num[i] < num[i + 1]){
                    count++;
                }
            }
        }
        
        System.out.println(count);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int count = 0;
        int num[] = new int[n];
        
        for(int i = 0; i < n; i++){
            num[i] = stdIn.nextInt();
        }
        
        for(int i = 1; i < n - 1; i++){
            if(num[i - 1] > num[i]){
                if(num[i] > num[i + 1]){
                    count++;
                }
            }else{
                if(num[i] < num[i + 1]){
                    count++;
                }
            }
        }
        
        System.out.println(count);
    }
}
