import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int n = Integer.parseInt(line);
        String line1 = sc.nextLine();
        String[] line2 = line1.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line2[i]);
        int count = 0;
        for(int i = 0; i < n - 2; i++){
            if(ary[i] < ary[i + 1]){
                if(ary[i + 1] < ary[i + 2])
                count++;
            }
            else if(ary[i] > ary[i + 1]){
                if(ary[i + 1] > ary[i + 2])
                count++;
            }
        }
        System.out.println(count);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int n = Integer.parseInt(line);
        String line1 = sc.nextLine();
        String[] line2 = line1.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line2[i]);
        int count = 0;
        for(int i = 0; i < n - 2; i++){
            if(ary[i] < ary[i + 1]){
                if(ary[i + 1] < ary[i + 2])
                count++;
            }
            else if(ary[i] > ary[i + 1]){
                if(ary[i + 1] > ary[i + 2])
                count++;
            }
        }
        System.out.println(count);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int n = Integer.parseInt(line);
        String line1 = sc.nextLine();
        String[] line2 = line1.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line2[i]);
        int count = 0;
        for(int i = 0; i < n - 2; i++){
            if(ary[i] < ary[i + 1]){
                if(ary[i + 1] < ary[i + 2])
                count++;
            }
            else if(ary[i] > ary[i + 1]){
                if(ary[i + 1] > ary[i + 2])
                count++;
            }
        }
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int n = Integer.parseInt(line);
        String line1 = sc.nextLine();
        String[] line2 = line1.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line2[i]);
        int count = 0;
        for(int i = 0; i < n - 2; i++){
            if(ary[i] < ary[i + 1]){
                if(ary[i + 1] < ary[i + 2])
                count++;
            }
            else if(ary[i] > ary[i + 1]){
                if(ary[i + 1] > ary[i + 2])
                count++;
            }
        }
        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc int n = Integer.parseInt(line); n Integer.parseInt(line) Integer.parseInt Integer line String line1 = sc.nextLine(); line1 sc.nextLine() sc.nextLine sc String[] line2 = line1.split(" "); line2 line1.split(" ") line1.split line1 " " int[] ary = new int[n]; ary new int[n] n for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line2[i]); int i = 0; int i = 0; i 0 i < n i n i++ i++ i ary[i] = Integer.parseInt(line2[i]); ary[i] = Integer.parseInt(line2[i]) ary[i] ary i Integer.parseInt(line2[i]) Integer.parseInt Integer line2[i] line2 i int count = 0; count 0 for(int i = 0; i < n - 2; i++){
            if(ary[i] < ary[i + 1]){
                if(ary[i + 1] < ary[i + 2])
                count++;
            }
            else if(ary[i] > ary[i + 1]){
                if(ary[i + 1] > ary[i + 2])
                count++;
            }
        } int i = 0; int i = 0; i 0 i < n - 2 i n - 2 n 2 i++ i++ i {
            if(ary[i] < ary[i + 1]){
                if(ary[i + 1] < ary[i + 2])
                count++;
            }
            else if(ary[i] > ary[i + 1]){
                if(ary[i + 1] > ary[i + 2])
                count++;
            }
        } {
            if(ary[i] < ary[i + 1]){
                if(ary[i + 1] < ary[i + 2])
                count++;
            }
            else if(ary[i] > ary[i + 1]){
                if(ary[i + 1] > ary[i + 2])
                count++;
            }
        } if(ary[i] < ary[i + 1]){
                if(ary[i + 1] < ary[i + 2])
                count++;
            }
            else if(ary[i] > ary[i + 1]){
                if(ary[i + 1] > ary[i + 2])
                count++;
            } ary[i] < ary[i + 1] ary[i] ary i ary[i + 1] ary i + 1 i 1 {
                if(ary[i + 1] < ary[i + 2])
                count++;
            } if(ary[i + 1] < ary[i + 2])
                count++; ary[i + 1] < ary[i + 2] ary[i + 1] ary i + 1 i 1 ary[i + 2] ary i + 2 i 2 count++ count if(ary[i] > ary[i + 1]){
                if(ary[i + 1] > ary[i + 2])
                count++;
            } ary[i] > ary[i + 1] ary[i] ary i ary[i + 1] ary i + 1 i 1 {
                if(ary[i + 1] > ary[i + 2])
                count++;
            } if(ary[i + 1] > ary[i + 2])
                count++; ary[i + 1] > ary[i + 2] ary[i + 1] ary i + 1 i 1 ary[i + 2] ary i + 2 i 2 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) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int n = Integer.parseInt(line);
        String line1 = sc.nextLine();
        String[] line2 = line1.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line2[i]);
        int count = 0;
        for(int i = 0; i < n - 2; i++){
            if(ary[i] < ary[i + 1]){
                if(ary[i + 1] < ary[i + 2])
                count++;
            }
            else if(ary[i] > ary[i + 1]){
                if(ary[i + 1] > ary[i + 2])
                count++;
            }
        }
        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int n = Integer.parseInt(line);
        String line1 = sc.nextLine();
        String[] line2 = line1.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line2[i]);
        int count = 0;
        for(int i = 0; i < n - 2; i++){
            if(ary[i] < ary[i + 1]){
                if(ary[i + 1] < ary[i + 2])
                count++;
            }
            else if(ary[i] > ary[i + 1]){
                if(ary[i + 1] > ary[i + 2])
                count++;
            }
        }
        System.out.println(count);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int n = Integer.parseInt(line);
        String line1 = sc.nextLine();
        String[] line2 = line1.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)
        ary[i] = Integer.parseInt(line2[i]);
        int count = 0;
        for(int i = 0; i < n - 2; i++){
            if(ary[i] < ary[i + 1]){
                if(ary[i + 1] < ary[i + 2])
                count++;
            }
            else if(ary[i] > ary[i + 1]){
                if(ary[i + 1] > ary[i + 2])
                count++;
            }
        }
        System.out.println(count);
    }
}