import java.util.Scanner;

public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] nums = new int[NUM];
        for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        }

        // search
        int count = 0;
        for(int i = 1; i < NUM - 1; i++){
            if((nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) || (nums[i - 1] > nums[i] && nums[i] > nums[i + 1])){
                count++;
            }
        }

        // answer
        System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] nums = new int[NUM];
        for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        }

        // search
        int count = 0;
        for(int i = 1; i < NUM - 1; i++){
            if((nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) || (nums[i - 1] > nums[i] && nums[i] > nums[i + 1])){
                count++;
            }
        }

        // answer
        System.out.println(count);
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] nums = new int[NUM];
        for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        }

        // search
        int count = 0;
        for(int i = 1; i < NUM - 1; i++){
            if((nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) || (nums[i - 1] > nums[i] && nums[i] > nums[i + 1])){
                count++;
            }
        }

        // answer
        System.out.println(count);
    } main {
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] nums = new int[NUM];
        for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        }

        // search
        int count = 0;
        for(int i = 1; i < NUM - 1; i++){
            if((nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) || (nums[i - 1] > nums[i] && nums[i] > nums[i + 1])){
                count++;
            }
        }

        // answer
        System.out.println(count);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) final int NUM = scan.nextInt(); NUM scan.nextInt() scan.nextInt scan int[] nums = new int[NUM]; nums new int[NUM] NUM for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        } int i = 0; int i = 0; i 0 i < NUM i NUM i++ i++ i {
            nums[i] = scan.nextInt();
        } {
            nums[i] = scan.nextInt();
        } nums[i] = scan.nextInt() nums[i] nums i scan.nextInt() scan.nextInt scan int count = 0; count 0 for(int i = 1; i < NUM - 1; i++){
            if((nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) || (nums[i - 1] > nums[i] && nums[i] > nums[i + 1])){
                count++;
            }
        } int i = 1; int i = 1; i 1 i < NUM - 1 i NUM - 1 NUM 1 i++ i++ i {
            if((nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) || (nums[i - 1] > nums[i] && nums[i] > nums[i + 1])){
                count++;
            }
        } {
            if((nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) || (nums[i - 1] > nums[i] && nums[i] > nums[i + 1])){
                count++;
            }
        } if((nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) || (nums[i - 1] > nums[i] && nums[i] > nums[i + 1])){
                count++;
            } (nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) || (nums[i - 1] > nums[i] && nums[i] > nums[i + 1]) (nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) nums[i - 1] < nums[i] nums[i - 1] nums i - 1 i 1 nums[i] nums i nums[i] < nums[i + 1] nums[i] nums i nums[i + 1] nums i + 1 i 1 (nums[i - 1] > nums[i] && nums[i] > nums[i + 1]) nums[i - 1] > nums[i] nums[i - 1] nums i - 1 i 1 nums[i] nums i nums[i] > nums[i + 1] nums[i] nums i nums[i + 1] nums 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 scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] nums = new int[NUM];
        for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        }

        // search
        int count = 0;
        for(int i = 1; i < NUM - 1; i++){
            if((nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) || (nums[i - 1] > nums[i] && nums[i] > nums[i + 1])){
                count++;
            }
        }

        // answer
        System.out.println(count);
    }
} public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] nums = new int[NUM];
        for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        }

        // search
        int count = 0;
        for(int i = 1; i < NUM - 1; i++){
            if((nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) || (nums[i - 1] > nums[i] && nums[i] > nums[i + 1])){
                count++;
            }
        }

        // answer
        System.out.println(count);
    }
} Main
import java.util.Scanner;

public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] nums = new int[NUM];
        for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        }

        // search
        int count = 0;
        for(int i = 1; i < NUM - 1; i++){
            if((nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) || (nums[i - 1] > nums[i] && nums[i] > nums[i + 1])){
                count++;
            }
        }

        // answer
        System.out.println(count);
    }
}