import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        boolean debug = false;
        if (debug != false) {
            return;
        }
        System.out.println(str);
    }

    public static void main(String[] args) {

        int  N;
        int[] pList;
        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            pList = new int[N];
            for(int i =0 ; i < N;i++){
                pList[i] = sc.nextInt();
            }
        }

        int result = 0;
        for(int i = 0 ; i < N -2;i ++){
            if(pList[i] < pList[i+1] && pList[i+2] > pList[i+1]){
                result++;
            }else if(pList[i] > pList[i+1] && pList[i+2] < pList[i+1]){
                result++;
            }
        }
        System.out.println(result);

    }

} import java.util.Scanner; Scanner java.util public class Main {
    public static void debug(String str) {
        boolean debug = false;
        if (debug != false) {
            return;
        }
        System.out.println(str);
    }

    public static void main(String[] args) {

        int  N;
        int[] pList;
        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            pList = new int[N];
            for(int i =0 ; i < N;i++){
                pList[i] = sc.nextInt();
            }
        }

        int result = 0;
        for(int i = 0 ; i < N -2;i ++){
            if(pList[i] < pList[i+1] && pList[i+2] > pList[i+1]){
                result++;
            }else if(pList[i] > pList[i+1] && pList[i+2] < pList[i+1]){
                result++;
            }
        }
        System.out.println(result);

    }

} Main public static void debug(String str) {
        boolean debug = false;
        if (debug != false) {
            return;
        }
        System.out.println(str);
    } debug {
        boolean debug = false;
        if (debug != false) {
            return;
        }
        System.out.println(str);
    } boolean debug = false; debug false if (debug != false) {
            return;
        } debug != false debug false {
            return;
        } return; System.out.println(str) System.out.println System.out System System.out str String str str public static void main(String[] args) {

        int  N;
        int[] pList;
        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            pList = new int[N];
            for(int i =0 ; i < N;i++){
                pList[i] = sc.nextInt();
            }
        }

        int result = 0;
        for(int i = 0 ; i < N -2;i ++){
            if(pList[i] < pList[i+1] && pList[i+2] > pList[i+1]){
                result++;
            }else if(pList[i] > pList[i+1] && pList[i+2] < pList[i+1]){
                result++;
            }
        }
        System.out.println(result);

    } main {

        int  N;
        int[] pList;
        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            pList = new int[N];
            for(int i =0 ; i < N;i++){
                pList[i] = sc.nextInt();
            }
        }

        int result = 0;
        for(int i = 0 ; i < N -2;i ++){
            if(pList[i] < pList[i+1] && pList[i+2] > pList[i+1]){
                result++;
            }else if(pList[i] > pList[i+1] && pList[i+2] < pList[i+1]){
                result++;
            }
        }
        System.out.println(result);

    } int  N; N int[] pList; pList try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            pList = new int[N];
            for(int i =0 ; i < N;i++){
                pList[i] = sc.nextInt();
            }
        } {
            N = sc.nextInt();
            pList = new int[N];
            for(int i =0 ; i < N;i++){
                pList[i] = sc.nextInt();
            }
        } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) N = sc.nextInt() N sc.nextInt() sc.nextInt sc pList = new int[N] pList new int[N] N for(int i =0 ; i < N;i++){
                pList[i] = sc.nextInt();
            } int i =0 ; int i =0 ; i 0 i < N i N i++ i++ i {
                pList[i] = sc.nextInt();
            } {
                pList[i] = sc.nextInt();
            } pList[i] = sc.nextInt() pList[i] pList i sc.nextInt() sc.nextInt sc int result = 0; result 0 for(int i = 0 ; i < N -2;i ++){
            if(pList[i] < pList[i+1] && pList[i+2] > pList[i+1]){
                result++;
            }else if(pList[i] > pList[i+1] && pList[i+2] < pList[i+1]){
                result++;
            }
        } int i = 0 ; int i = 0 ; i 0 i < N -2 i N -2 N 2 i ++ i ++ i {
            if(pList[i] < pList[i+1] && pList[i+2] > pList[i+1]){
                result++;
            }else if(pList[i] > pList[i+1] && pList[i+2] < pList[i+1]){
                result++;
            }
        } {
            if(pList[i] < pList[i+1] && pList[i+2] > pList[i+1]){
                result++;
            }else if(pList[i] > pList[i+1] && pList[i+2] < pList[i+1]){
                result++;
            }
        } if(pList[i] < pList[i+1] && pList[i+2] > pList[i+1]){
                result++;
            }else if(pList[i] > pList[i+1] && pList[i+2] < pList[i+1]){
                result++;
            } pList[i] < pList[i+1] && pList[i+2] > pList[i+1] pList[i] < pList[i+1] pList[i] pList i pList[i+1] pList i+1 i 1 pList[i+2] > pList[i+1] pList[i+2] pList i+2 i 2 pList[i+1] pList i+1 i 1 {
                result++;
            } result++ result if(pList[i] > pList[i+1] && pList[i+2] < pList[i+1]){
                result++;
            } pList[i] > pList[i+1] && pList[i+2] < pList[i+1] pList[i] > pList[i+1] pList[i] pList i pList[i+1] pList i+1 i 1 pList[i+2] < pList[i+1] pList[i+2] pList i+2 i 2 pList[i+1] pList i+1 i 1 {
                result++;
            } result++ result System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {
    public static void debug(String str) {
        boolean debug = false;
        if (debug != false) {
            return;
        }
        System.out.println(str);
    }

    public static void main(String[] args) {

        int  N;
        int[] pList;
        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            pList = new int[N];
            for(int i =0 ; i < N;i++){
                pList[i] = sc.nextInt();
            }
        }

        int result = 0;
        for(int i = 0 ; i < N -2;i ++){
            if(pList[i] < pList[i+1] && pList[i+2] > pList[i+1]){
                result++;
            }else if(pList[i] > pList[i+1] && pList[i+2] < pList[i+1]){
                result++;
            }
        }
        System.out.println(result);

    }

} public class Main {
    public static void debug(String str) {
        boolean debug = false;
        if (debug != false) {
            return;
        }
        System.out.println(str);
    }

    public static void main(String[] args) {

        int  N;
        int[] pList;
        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            pList = new int[N];
            for(int i =0 ; i < N;i++){
                pList[i] = sc.nextInt();
            }
        }

        int result = 0;
        for(int i = 0 ; i < N -2;i ++){
            if(pList[i] < pList[i+1] && pList[i+2] > pList[i+1]){
                result++;
            }else if(pList[i] > pList[i+1] && pList[i+2] < pList[i+1]){
                result++;
            }
        }
        System.out.println(result);

    }

} Main
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        boolean debug = false;
        if (debug != false) {
            return;
        }
        System.out.println(str);
    }

    public static void main(String[] args) {

        int  N;
        int[] pList;
        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            pList = new int[N];
            for(int i =0 ; i < N;i++){
                pList[i] = sc.nextInt();
            }
        }

        int result = 0;
        for(int i = 0 ; i < N -2;i ++){
            if(pList[i] < pList[i+1] && pList[i+2] > pList[i+1]){
                result++;
            }else if(pList[i] > pList[i+1] && pList[i+2] < pList[i+1]){
                result++;
            }
        }
        System.out.println(result);

    }

}
