import java.util.HashMap;
import java.util.Scanner;

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

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

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

    } main {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int nums[] = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = input.nextInt();
        }
        int count =0;
        for(int i = 1;i<n-1;i++){
            if(nums[i] <= nums[i+1]&&nums[i] >= nums[i-1])
                count++;
            else if(nums[i] >= nums[i+1]&&nums[i] <= nums[i-1])
                count++;
        }
        System.out.println(count);

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

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

    }
} Main
import java.util.HashMap;
import java.util.Scanner;

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

    }
}
