import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        new Main().run();
    }
    int[] p;

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        p = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = scanner.nextInt();
        }
        int ans = 0;
        for(int i = 1; i < n-1; i++) {
            ans += check(i);
        }
        System.out.println(ans);
    }

    private int check(int i) {
        if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i+1] < p[i] && p[i] < p[i-1])) {
            return 1;
        }
        return 0;
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args){
        new Main().run();
    }
    int[] p;

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        p = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = scanner.nextInt();
        }
        int ans = 0;
        for(int i = 1; i < n-1; i++) {
            ans += check(i);
        }
        System.out.println(ans);
    }

    private int check(int i) {
        if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i+1] < p[i] && p[i] < p[i-1])) {
            return 1;
        }
        return 0;
    }
} Main int[] p; p public static void main(String[] args){
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args private void run() {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        p = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = scanner.nextInt();
        }
        int ans = 0;
        for(int i = 1; i < n-1; i++) {
            ans += check(i);
        }
        System.out.println(ans);
    } run {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        p = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = scanner.nextInt();
        }
        int ans = 0;
        for(int i = 1; i < n-1; i++) {
            ans += check(i);
        }
        System.out.println(ans);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner p = new int[n] p new int[n] n for(int i = 0; i < n; i++){
            p[i] = scanner.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            p[i] = scanner.nextInt();
        } {
            p[i] = scanner.nextInt();
        } p[i] = scanner.nextInt() p[i] p i scanner.nextInt() scanner.nextInt scanner int ans = 0; ans 0 for(int i = 1; i < n-1; i++) {
            ans += check(i);
        } int i = 1; int i = 1; i 1 i < n-1 i n-1 n 1 i++ i++ i {
            ans += check(i);
        } {
            ans += check(i);
        } ans += check(i) ans check(i) check i System.out.println(ans) System.out.println System.out System System.out ans private int check(int i) {
        if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i+1] < p[i] && p[i] < p[i-1])) {
            return 1;
        }
        return 0;
    } check {
        if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i+1] < p[i] && p[i] < p[i-1])) {
            return 1;
        }
        return 0;
    } if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i+1] < p[i] && p[i] < p[i-1])) {
            return 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] < 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 {
            return 1;
        } return 1; 1 return 0; 0 int i i public class Main {
    public static void main(String[] args){
        new Main().run();
    }
    int[] p;

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        p = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = scanner.nextInt();
        }
        int ans = 0;
        for(int i = 1; i < n-1; i++) {
            ans += check(i);
        }
        System.out.println(ans);
    }

    private int check(int i) {
        if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i+1] < p[i] && p[i] < p[i-1])) {
            return 1;
        }
        return 0;
    }
} public class Main {
    public static void main(String[] args){
        new Main().run();
    }
    int[] p;

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        p = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = scanner.nextInt();
        }
        int ans = 0;
        for(int i = 1; i < n-1; i++) {
            ans += check(i);
        }
        System.out.println(ans);
    }

    private int check(int i) {
        if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i+1] < p[i] && p[i] < p[i-1])) {
            return 1;
        }
        return 0;
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        new Main().run();
    }
    int[] p;

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        p = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = scanner.nextInt();
        }
        int ans = 0;
        for(int i = 1; i < n-1; i++) {
            ans += check(i);
        }
        System.out.println(ans);
    }

    private int check(int i) {
        if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i+1] < p[i] && p[i] < p[i-1])) {
            return 1;
        }
        return 0;
    }
}