import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 11:09-

            int n = sc.nextInt();
            int[] vs = new int[n];

            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int cnt = 0;
            for (int i = 1; i < n - 1; i++) {
                if (vs[i] > vs[i - 1] && vs[i] < vs[i + 1] ||
                        vs[i] < vs[i - 1] && vs[i] > vs[i + 1]) {
                    cnt++;
                }
            }

            out.println(cnt);
        }
    }
} import java.io.BufferedInputStream; BufferedInputStream java.io import java.io.BufferedOutputStream; BufferedOutputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 11:09-

            int n = sc.nextInt();
            int[] vs = new int[n];

            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int cnt = 0;
            for (int i = 1; i < n - 1; i++) {
                if (vs[i] > vs[i - 1] && vs[i] < vs[i + 1] ||
                        vs[i] < vs[i - 1] && vs[i] > vs[i + 1]) {
                    cnt++;
                }
            }

            out.println(cnt);
        }
    }
} Main public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 11:09-

            int n = sc.nextInt();
            int[] vs = new int[n];

            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int cnt = 0;
            for (int i = 1; i < n - 1; i++) {
                if (vs[i] > vs[i - 1] && vs[i] < vs[i + 1] ||
                        vs[i] < vs[i - 1] && vs[i] > vs[i + 1]) {
                    cnt++;
                }
            }

            out.println(cnt);
        }
    } main {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 11:09-

            int n = sc.nextInt();
            int[] vs = new int[n];

            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int cnt = 0;
            for (int i = 1; i < n - 1; i++) {
                if (vs[i] > vs[i - 1] && vs[i] < vs[i + 1] ||
                        vs[i] < vs[i - 1] && vs[i] > vs[i + 1]) {
                    cnt++;
                }
            }

            out.println(cnt);
        }
    } try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 11:09-

            int n = sc.nextInt();
            int[] vs = new int[n];

            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int cnt = 0;
            for (int i = 1; i < n - 1; i++) {
                if (vs[i] > vs[i - 1] && vs[i] < vs[i + 1] ||
                        vs[i] < vs[i - 1] && vs[i] > vs[i + 1]) {
                    cnt++;
                }
            }

            out.println(cnt);
        } {

            Scanner sc = new Scanner(in);

            // 11:09-

            int n = sc.nextInt();
            int[] vs = new int[n];

            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int cnt = 0;
            for (int i = 1; i < n - 1; i++) {
                if (vs[i] > vs[i - 1] && vs[i] < vs[i + 1] ||
                        vs[i] < vs[i - 1] && vs[i] > vs[i + 1]) {
                    cnt++;
                }
            }

            out.println(cnt);
        } BufferedInputStream in = new BufferedInputStream(System.in) BufferedInputStream in = new BufferedInputStream(System.in) new BufferedInputStream(System.in) PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)) PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)) new PrintWriter(new BufferedOutputStream(System.out)) Scanner sc = new Scanner(in); sc new Scanner(in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] vs = new int[n]; vs new int[n] n for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < vs.length i vs.length vs vs.length i++ i++ i vs[i] = sc.nextInt(); vs[i] = sc.nextInt() vs[i] vs i sc.nextInt() sc.nextInt sc int cnt = 0; cnt 0 for (int i = 1; i < n - 1; i++) {
                if (vs[i] > vs[i - 1] && vs[i] < vs[i + 1] ||
                        vs[i] < vs[i - 1] && vs[i] > vs[i + 1]) {
                    cnt++;
                }
            } int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i {
                if (vs[i] > vs[i - 1] && vs[i] < vs[i + 1] ||
                        vs[i] < vs[i - 1] && vs[i] > vs[i + 1]) {
                    cnt++;
                }
            } {
                if (vs[i] > vs[i - 1] && vs[i] < vs[i + 1] ||
                        vs[i] < vs[i - 1] && vs[i] > vs[i + 1]) {
                    cnt++;
                }
            } if (vs[i] > vs[i - 1] && vs[i] < vs[i + 1] ||
                        vs[i] < vs[i - 1] && vs[i] > vs[i + 1]) {
                    cnt++;
                } vs[i] > vs[i - 1] && vs[i] < vs[i + 1] ||
                        vs[i] < vs[i - 1] && vs[i] > vs[i + 1] vs[i] > vs[i - 1] && vs[i] < vs[i + 1] vs[i] > vs[i - 1] vs[i] vs i vs[i - 1] vs i - 1 i 1 vs[i] < vs[i + 1] vs[i] vs i vs[i + 1] vs i + 1 i 1 vs[i] < vs[i - 1] && vs[i] > vs[i + 1] vs[i] < vs[i - 1] vs[i] vs i vs[i - 1] vs i - 1 i 1 vs[i] > vs[i + 1] vs[i] vs i vs[i + 1] vs i + 1 i 1 {
                    cnt++;
                } cnt++ cnt out.println(cnt) out.println out cnt String[] args args public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 11:09-

            int n = sc.nextInt();
            int[] vs = new int[n];

            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int cnt = 0;
            for (int i = 1; i < n - 1; i++) {
                if (vs[i] > vs[i - 1] && vs[i] < vs[i + 1] ||
                        vs[i] < vs[i - 1] && vs[i] > vs[i + 1]) {
                    cnt++;
                }
            }

            out.println(cnt);
        }
    }
} public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 11:09-

            int n = sc.nextInt();
            int[] vs = new int[n];

            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int cnt = 0;
            for (int i = 1; i < n - 1; i++) {
                if (vs[i] > vs[i - 1] && vs[i] < vs[i + 1] ||
                        vs[i] < vs[i - 1] && vs[i] > vs[i + 1]) {
                    cnt++;
                }
            }

            out.println(cnt);
        }
    }
} Main
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 11:09-

            int n = sc.nextInt();
            int[] vs = new int[n];

            for (int i = 0; i < vs.length; i++) vs[i] = sc.nextInt();

            int cnt = 0;
            for (int i = 1; i < n - 1; i++) {
                if (vs[i] > vs[i - 1] && vs[i] < vs[i + 1] ||
                        vs[i] < vs[i - 1] && vs[i] > vs[i + 1]) {
                    cnt++;
                }
            }

            out.println(cnt);
        }
    }
}
