import java.util.Scanner;

public final class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int[] p = new int[n];
        for(int i=0; i<p.length; i++){
            p[i] = stdIn.nextInt();
        }
        int counter = 0;

        for(int i=1; i<p.length-1; i++){
            if((p[i-1] < p[i] && p[i] <= p[i+1]) || (p[i+1] < p[i] && p[i] <= p[i-1])){
                counter++;
            }
        }

        System.out.println(counter);
    }
} import java.util.Scanner; Scanner java.util public final class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int[] p = new int[n];
        for(int i=0; i<p.length; i++){
            p[i] = stdIn.nextInt();
        }
        int counter = 0;

        for(int i=1; i<p.length-1; i++){
            if((p[i-1] < p[i] && p[i] <= p[i+1]) || (p[i+1] < p[i] && p[i] <= p[i-1])){
                counter++;
            }
        }

        System.out.println(counter);
    }
} Main public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int[] p = new int[n];
        for(int i=0; i<p.length; i++){
            p[i] = stdIn.nextInt();
        }
        int counter = 0;

        for(int i=1; i<p.length-1; i++){
            if((p[i-1] < p[i] && p[i] <= p[i+1]) || (p[i+1] < p[i] && p[i] <= p[i-1])){
                counter++;
            }
        }

        System.out.println(counter);
    } main {
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int[] p = new int[n];
        for(int i=0; i<p.length; i++){
            p[i] = stdIn.nextInt();
        }
        int counter = 0;

        for(int i=1; i<p.length-1; i++){
            if((p[i-1] < p[i] && p[i] <= p[i+1]) || (p[i+1] < p[i] && p[i] <= p[i-1])){
                counter++;
            }
        }

        System.out.println(counter);
    } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int[] p = new int[n]; p new int[n] n for(int i=0; i<p.length; i++){
            p[i] = stdIn.nextInt();
        } int i=0; int i=0; i 0 i<p.length i p.length p p.length i++ i++ i {
            p[i] = stdIn.nextInt();
        } {
            p[i] = stdIn.nextInt();
        } p[i] = stdIn.nextInt() p[i] p i stdIn.nextInt() stdIn.nextInt stdIn int counter = 0; counter 0 for(int i=1; i<p.length-1; i++){
            if((p[i-1] < p[i] && p[i] <= p[i+1]) || (p[i+1] < p[i] && p[i] <= p[i-1])){
                counter++;
            }
        } int i=1; int i=1; i 1 i<p.length-1 i p.length-1 p.length p p.length 1 i++ i++ i {
            if((p[i-1] < p[i] && p[i] <= p[i+1]) || (p[i+1] < p[i] && p[i] <= p[i-1])){
                counter++;
            }
        } {
            if((p[i-1] < p[i] && p[i] <= p[i+1]) || (p[i+1] < p[i] && p[i] <= p[i-1])){
                counter++;
            }
        } if((p[i-1] < p[i] && p[i] <= p[i+1]) || (p[i+1] < p[i] && p[i] <= p[i-1])){
                counter++;
            } (p[i-1] < p[i] && p[i] <= p[i+1]) || (p[i+1] < p[i] && p[i] <= p[i-1]) (p[i-1] < p[i] && p[i] <= p[i+1]) p[i-1] < p[i] p[i-1] p i-1 i 1 p[i] p i p[i] <= p[i+1] p[i] p i p[i+1] p i+1 i 1 (p[i+1] < p[i] && p[i] <= p[i-1]) p[i+1] < p[i] p[i+1] p i+1 i 1 p[i] p i p[i] <= p[i-1] p[i] p i p[i-1] p i-1 i 1 {
                counter++;
            } counter++ counter System.out.println(counter) System.out.println System.out System System.out counter String[] args args public final class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int[] p = new int[n];
        for(int i=0; i<p.length; i++){
            p[i] = stdIn.nextInt();
        }
        int counter = 0;

        for(int i=1; i<p.length-1; i++){
            if((p[i-1] < p[i] && p[i] <= p[i+1]) || (p[i+1] < p[i] && p[i] <= p[i-1])){
                counter++;
            }
        }

        System.out.println(counter);
    }
} public final class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int[] p = new int[n];
        for(int i=0; i<p.length; i++){
            p[i] = stdIn.nextInt();
        }
        int counter = 0;

        for(int i=1; i<p.length-1; i++){
            if((p[i-1] < p[i] && p[i] <= p[i+1]) || (p[i+1] < p[i] && p[i] <= p[i-1])){
                counter++;
            }
        }

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

public final class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int[] p = new int[n];
        for(int i=0; i<p.length; i++){
            p[i] = stdIn.nextInt();
        }
        int counter = 0;

        for(int i=1; i<p.length-1; i++){
            if((p[i-1] < p[i] && p[i] <= p[i+1]) || (p[i+1] < p[i] && p[i] <= p[i-1])){
                counter++;
            }
        }

        System.out.println(counter);
    }
}