import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final int MAX = 100100;
    InputStream in = System.in;
    PrintStream out = System.out;
    // static int dp[][] = new int[MAX][MAX];
    static int p[] = new int[20];

    public void _main(String[] args) {
        Scanner sc = new Scanner(in);
        int n = sc.nextInt();
        int cnt=0;
        for (int i=0;i<n;i++) {
            p[i] = sc.nextInt();
        }
        for (int i=1;i<n-1;i++) {
            if (p[i-1] < p[i] && p[i] < p[i+1]) cnt++;
            else if (p[i+1]<p[i]&&p[i]<p[i-1]) cnt++;
        }
        out.println(cnt);
    }

    public static void main(String[] args) {
        new Main()._main(args);
    }
} import java.io.InputStream; InputStream java.io import java.io.PrintStream; PrintStream java.io import java.util.Scanner; Scanner java.util public class Main {
    static final int MAX = 100100;
    InputStream in = System.in;
    PrintStream out = System.out;
    // static int dp[][] = new int[MAX][MAX];
    static int p[] = new int[20];

    public void _main(String[] args) {
        Scanner sc = new Scanner(in);
        int n = sc.nextInt();
        int cnt=0;
        for (int i=0;i<n;i++) {
            p[i] = sc.nextInt();
        }
        for (int i=1;i<n-1;i++) {
            if (p[i-1] < p[i] && p[i] < p[i+1]) cnt++;
            else if (p[i+1]<p[i]&&p[i]<p[i-1]) cnt++;
        }
        out.println(cnt);
    }

    public static void main(String[] args) {
        new Main()._main(args);
    }
} Main static final int MAX = 100100; MAX 100100 InputStream in = System.in; in System.in System System.in PrintStream out = System.out; out System.out System System.out // static int dp[][] = new int[MAX][MAX];
    static int p[] = new int[20]; p new int[20] 20 public void _main(String[] args) {
        Scanner sc = new Scanner(in);
        int n = sc.nextInt();
        int cnt=0;
        for (int i=0;i<n;i++) {
            p[i] = sc.nextInt();
        }
        for (int i=1;i<n-1;i++) {
            if (p[i-1] < p[i] && p[i] < p[i+1]) cnt++;
            else if (p[i+1]<p[i]&&p[i]<p[i-1]) cnt++;
        }
        out.println(cnt);
    } _main {
        Scanner sc = new Scanner(in);
        int n = sc.nextInt();
        int cnt=0;
        for (int i=0;i<n;i++) {
            p[i] = sc.nextInt();
        }
        for (int i=1;i<n-1;i++) {
            if (p[i-1] < p[i] && p[i] < p[i+1]) cnt++;
            else if (p[i+1]<p[i]&&p[i]<p[i-1]) cnt++;
        }
        out.println(cnt);
    } Scanner sc = new Scanner(in); sc new Scanner(in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int cnt=0; cnt 0 for (int i=0;i<n;i++) {
            p[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            p[i] = sc.nextInt();
        } {
            p[i] = sc.nextInt();
        } p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc for (int i=1;i<n-1;i++) {
            if (p[i-1] < p[i] && p[i] < p[i+1]) cnt++;
            else if (p[i+1]<p[i]&&p[i]<p[i-1]) cnt++;
        } int i=1; int i=1; i 1 i<n-1 i n-1 n 1 i++ i++ i {
            if (p[i-1] < p[i] && p[i] < p[i+1]) cnt++;
            else if (p[i+1]<p[i]&&p[i]<p[i-1]) cnt++;
        } {
            if (p[i-1] < p[i] && p[i] < p[i+1]) cnt++;
            else if (p[i+1]<p[i]&&p[i]<p[i-1]) cnt++;
        } if (p[i-1] < p[i] && p[i] < p[i+1]) cnt++;
            else if (p[i+1]<p[i]&&p[i]<p[i-1]) cnt++; p[i-1] < p[i] && p[i] < p[i+1] p[i-1] < p[i] p[i-1] p i-1 i 1 p[i] p i p[i] < p[i+1] p[i] p i p[i+1] p i+1 i 1 cnt++ cnt if (p[i+1]<p[i]&&p[i]<p[i-1]) cnt++; p[i+1]<p[i]&&p[i]<p[i-1] p[i+1]<p[i] p[i+1] p i+1 i 1 p[i] p i p[i]<p[i-1] p[i] p i p[i-1] p i-1 i 1 cnt++ cnt out.println(cnt) out.println out cnt String[] args args public static void main(String[] args) {
        new Main()._main(args);
    } main {
        new Main()._main(args);
    } new Main()._main(args) new Main()._main new Main() args String[] args args public class Main {
    static final int MAX = 100100;
    InputStream in = System.in;
    PrintStream out = System.out;
    // static int dp[][] = new int[MAX][MAX];
    static int p[] = new int[20];

    public void _main(String[] args) {
        Scanner sc = new Scanner(in);
        int n = sc.nextInt();
        int cnt=0;
        for (int i=0;i<n;i++) {
            p[i] = sc.nextInt();
        }
        for (int i=1;i<n-1;i++) {
            if (p[i-1] < p[i] && p[i] < p[i+1]) cnt++;
            else if (p[i+1]<p[i]&&p[i]<p[i-1]) cnt++;
        }
        out.println(cnt);
    }

    public static void main(String[] args) {
        new Main()._main(args);
    }
} public class Main {
    static final int MAX = 100100;
    InputStream in = System.in;
    PrintStream out = System.out;
    // static int dp[][] = new int[MAX][MAX];
    static int p[] = new int[20];

    public void _main(String[] args) {
        Scanner sc = new Scanner(in);
        int n = sc.nextInt();
        int cnt=0;
        for (int i=0;i<n;i++) {
            p[i] = sc.nextInt();
        }
        for (int i=1;i<n-1;i++) {
            if (p[i-1] < p[i] && p[i] < p[i+1]) cnt++;
            else if (p[i+1]<p[i]&&p[i]<p[i-1]) cnt++;
        }
        out.println(cnt);
    }

    public static void main(String[] args) {
        new Main()._main(args);
    }
} Main
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final int MAX = 100100;
    InputStream in = System.in;
    PrintStream out = System.out;
    // static int dp[][] = new int[MAX][MAX];
    static int p[] = new int[20];

    public void _main(String[] args) {
        Scanner sc = new Scanner(in);
        int n = sc.nextInt();
        int cnt=0;
        for (int i=0;i<n;i++) {
            p[i] = sc.nextInt();
        }
        for (int i=1;i<n-1;i++) {
            if (p[i-1] < p[i] && p[i] < p[i+1]) cnt++;
            else if (p[i+1]<p[i]&&p[i]<p[i-1]) cnt++;
        }
        out.println(cnt);
    }

    public static void main(String[] args) {
        new Main()._main(args);
    }
}
