import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int total = Integer.parseInt(sc.next());
        List<Integer> list = new ArrayList<>();
        for (int x =1; x <= total ; x++) {
            list.add(Integer.parseInt(sc.next()));
        }
        int res = 0;
        for (int x =1; x <= total-2 ; x++) {
            int first = list.get(x-1);
            int second = list.get(x);
            int third = list.get(x+1);
            if (first<second && second<third) {
                res++;
            }
            if (second<first && third<second) {
                res++;
            }
        }
        System.out.println(res);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int total = Integer.parseInt(sc.next());
        List<Integer> list = new ArrayList<>();
        for (int x =1; x <= total ; x++) {
            list.add(Integer.parseInt(sc.next()));
        }
        int res = 0;
        for (int x =1; x <= total-2 ; x++) {
            int first = list.get(x-1);
            int second = list.get(x);
            int third = list.get(x+1);
            if (first<second && second<third) {
                res++;
            }
            if (second<first && third<second) {
                res++;
            }
        }
        System.out.println(res);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int total = Integer.parseInt(sc.next());
        List<Integer> list = new ArrayList<>();
        for (int x =1; x <= total ; x++) {
            list.add(Integer.parseInt(sc.next()));
        }
        int res = 0;
        for (int x =1; x <= total-2 ; x++) {
            int first = list.get(x-1);
            int second = list.get(x);
            int third = list.get(x+1);
            if (first<second && second<third) {
                res++;
            }
            if (second<first && third<second) {
                res++;
            }
        }
        System.out.println(res);
    } main {
        Scanner sc = new Scanner(System.in);
        int total = Integer.parseInt(sc.next());
        List<Integer> list = new ArrayList<>();
        for (int x =1; x <= total ; x++) {
            list.add(Integer.parseInt(sc.next()));
        }
        int res = 0;
        for (int x =1; x <= total-2 ; x++) {
            int first = list.get(x-1);
            int second = list.get(x);
            int third = list.get(x+1);
            if (first<second && second<third) {
                res++;
            }
            if (second<first && third<second) {
                res++;
            }
        }
        System.out.println(res);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int total = Integer.parseInt(sc.next()); total Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc List<Integer> list = new ArrayList<>(); list new ArrayList<>() for (int x =1; x <= total ; x++) {
            list.add(Integer.parseInt(sc.next()));
        } int x =1; int x =1; x 1 x <= total x total x++ x++ x {
            list.add(Integer.parseInt(sc.next()));
        } {
            list.add(Integer.parseInt(sc.next()));
        } list.add(Integer.parseInt(sc.next())) list.add list Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int res = 0; res 0 for (int x =1; x <= total-2 ; x++) {
            int first = list.get(x-1);
            int second = list.get(x);
            int third = list.get(x+1);
            if (first<second && second<third) {
                res++;
            }
            if (second<first && third<second) {
                res++;
            }
        } int x =1; int x =1; x 1 x <= total-2 x total-2 total 2 x++ x++ x {
            int first = list.get(x-1);
            int second = list.get(x);
            int third = list.get(x+1);
            if (first<second && second<third) {
                res++;
            }
            if (second<first && third<second) {
                res++;
            }
        } {
            int first = list.get(x-1);
            int second = list.get(x);
            int third = list.get(x+1);
            if (first<second && second<third) {
                res++;
            }
            if (second<first && third<second) {
                res++;
            }
        } int first = list.get(x-1); first list.get(x-1) list.get list x-1 x 1 int second = list.get(x); second list.get(x) list.get list x int third = list.get(x+1); third list.get(x+1) list.get list x+1 x 1 if (first<second && second<third) {
                res++;
            } first<second && second<third first<second first second second<third second third {
                res++;
            } res++ res if (second<first && third<second) {
                res++;
            } second<first && third<second second<first second first third<second third second {
                res++;
            } res++ res System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int total = Integer.parseInt(sc.next());
        List<Integer> list = new ArrayList<>();
        for (int x =1; x <= total ; x++) {
            list.add(Integer.parseInt(sc.next()));
        }
        int res = 0;
        for (int x =1; x <= total-2 ; x++) {
            int first = list.get(x-1);
            int second = list.get(x);
            int third = list.get(x+1);
            if (first<second && second<third) {
                res++;
            }
            if (second<first && third<second) {
                res++;
            }
        }
        System.out.println(res);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int total = Integer.parseInt(sc.next());
        List<Integer> list = new ArrayList<>();
        for (int x =1; x <= total ; x++) {
            list.add(Integer.parseInt(sc.next()));
        }
        int res = 0;
        for (int x =1; x <= total-2 ; x++) {
            int first = list.get(x-1);
            int second = list.get(x);
            int third = list.get(x+1);
            if (first<second && second<third) {
                res++;
            }
            if (second<first && third<second) {
                res++;
            }
        }
        System.out.println(res);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int total = Integer.parseInt(sc.next());
        List<Integer> list = new ArrayList<>();
        for (int x =1; x <= total ; x++) {
            list.add(Integer.parseInt(sc.next()));
        }
        int res = 0;
        for (int x =1; x <= total-2 ; x++) {
            int first = list.get(x-1);
            int second = list.get(x);
            int third = list.get(x+1);
            if (first<second && second<third) {
                res++;
            }
            if (second<first && third<second) {
                res++;
            }
        }
        System.out.println(res);
    }
}
