import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] array= new int[n];

        for(int i= 0; i < n;i++){
            array[i] = scan.nextInt();
        }

        int ans = 0;
        for(int i= 0; i <= n-3 ;i++){

            if( array[i] < array[i+1] && array[i+1] < array[i+2]){

                ans++;

            }else if(array[i] > array[i+1] && array[i+1] > array[i+2]) {

                ans++;
            }
        }

        System.out.println(ans);




        return;

    }
} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] array= new int[n];

        for(int i= 0; i < n;i++){
            array[i] = scan.nextInt();
        }

        int ans = 0;
        for(int i= 0; i <= n-3 ;i++){

            if( array[i] < array[i+1] && array[i+1] < array[i+2]){

                ans++;

            }else if(array[i] > array[i+1] && array[i+1] > array[i+2]) {

                ans++;
            }
        }

        System.out.println(ans);




        return;

    }
} Main public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] array= new int[n];

        for(int i= 0; i < n;i++){
            array[i] = scan.nextInt();
        }

        int ans = 0;
        for(int i= 0; i <= n-3 ;i++){

            if( array[i] < array[i+1] && array[i+1] < array[i+2]){

                ans++;

            }else if(array[i] > array[i+1] && array[i+1] > array[i+2]) {

                ans++;
            }
        }

        System.out.println(ans);




        return;

    } main {

        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] array= new int[n];

        for(int i= 0; i < n;i++){
            array[i] = scan.nextInt();
        }

        int ans = 0;
        for(int i= 0; i <= n-3 ;i++){

            if( array[i] < array[i+1] && array[i+1] < array[i+2]){

                ans++;

            }else if(array[i] > array[i+1] && array[i+1] > array[i+2]) {

                ans++;
            }
        }

        System.out.println(ans);




        return;

    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] array= new int[n]; array new int[n] n for(int i= 0; i < n;i++){
            array[i] = scan.nextInt();
        } int i= 0; int i= 0; i 0 i < n i n i++ i++ i {
            array[i] = scan.nextInt();
        } {
            array[i] = scan.nextInt();
        } array[i] = scan.nextInt() array[i] array i scan.nextInt() scan.nextInt scan int ans = 0; ans 0 for(int i= 0; i <= n-3 ;i++){

            if( array[i] < array[i+1] && array[i+1] < array[i+2]){

                ans++;

            }else if(array[i] > array[i+1] && array[i+1] > array[i+2]) {

                ans++;
            }
        } int i= 0; int i= 0; i 0 i <= n-3 i n-3 n 3 i++ i++ i {

            if( array[i] < array[i+1] && array[i+1] < array[i+2]){

                ans++;

            }else if(array[i] > array[i+1] && array[i+1] > array[i+2]) {

                ans++;
            }
        } {

            if( array[i] < array[i+1] && array[i+1] < array[i+2]){

                ans++;

            }else if(array[i] > array[i+1] && array[i+1] > array[i+2]) {

                ans++;
            }
        } if( array[i] < array[i+1] && array[i+1] < array[i+2]){

                ans++;

            }else if(array[i] > array[i+1] && array[i+1] > array[i+2]) {

                ans++;
            } array[i] < array[i+1] && array[i+1] < array[i+2] array[i] < array[i+1] array[i] array i array[i+1] array i+1 i 1 array[i+1] < array[i+2] array[i+1] array i+1 i 1 array[i+2] array i+2 i 2 {

                ans++;

            } ans++ ans if(array[i] > array[i+1] && array[i+1] > array[i+2]) {

                ans++;
            } array[i] > array[i+1] && array[i+1] > array[i+2] array[i] > array[i+1] array[i] array i array[i+1] array i+1 i 1 array[i+1] > array[i+2] array[i+1] array i+1 i 1 array[i+2] array i+2 i 2 {

                ans++;
            } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans return; String[] args args public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] array= new int[n];

        for(int i= 0; i < n;i++){
            array[i] = scan.nextInt();
        }

        int ans = 0;
        for(int i= 0; i <= n-3 ;i++){

            if( array[i] < array[i+1] && array[i+1] < array[i+2]){

                ans++;

            }else if(array[i] > array[i+1] && array[i+1] > array[i+2]) {

                ans++;
            }
        }

        System.out.println(ans);




        return;

    }
} public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] array= new int[n];

        for(int i= 0; i < n;i++){
            array[i] = scan.nextInt();
        }

        int ans = 0;
        for(int i= 0; i <= n-3 ;i++){

            if( array[i] < array[i+1] && array[i+1] < array[i+2]){

                ans++;

            }else if(array[i] > array[i+1] && array[i+1] > array[i+2]) {

                ans++;
            }
        }

        System.out.println(ans);




        return;

    }
} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] array= new int[n];

        for(int i= 0; i < n;i++){
            array[i] = scan.nextInt();
        }

        int ans = 0;
        for(int i= 0; i <= n-3 ;i++){

            if( array[i] < array[i+1] && array[i+1] < array[i+2]){

                ans++;

            }else if(array[i] > array[i+1] && array[i+1] > array[i+2]) {

                ans++;
            }
        }

        System.out.println(ans);




        return;

    }
}