import javax.print.DocFlavor;
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = nextInt();

        int[] p = new int[n];
        p[0] = nextInt();
        p[1] = nextInt();
        int count = 0;
        for(int i=2; i<n; i++){
            p[i] = nextInt();
            if(p[i-2] <= p[i-1] && p[i-1] < p[i] || p[i] <= p[i-1] && p[i-1] < p[i-2]){
                count++;
            }
        }
        println(count);
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
} import javax.print.DocFlavor; DocFlavor javax.print import java.awt.*; awt.* java import java.io.PrintWriter; PrintWriter java.io import java.lang.reflect.Array; Array java.lang.reflect import java.math.BigInteger; BigInteger java.math import java.util.*; util.* java import java.util.List; List java.util public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = nextInt();

        int[] p = new int[n];
        p[0] = nextInt();
        p[1] = nextInt();
        int count = 0;
        for(int i=2; i<n; i++){
            p[i] = nextInt();
            if(p[i-2] <= p[i-1] && p[i-1] < p[i] || p[i] <= p[i-1] && p[i-1] < p[i-2]){
                count++;
            }
        }
        println(count);
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
} Main static String br = System.getProperty("line.separator"); br System.getProperty("line.separator") System.getProperty System "line.separator" static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) static PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) public static void main(String[] args) {
        int n = nextInt();

        int[] p = new int[n];
        p[0] = nextInt();
        p[1] = nextInt();
        int count = 0;
        for(int i=2; i<n; i++){
            p[i] = nextInt();
            if(p[i-2] <= p[i-1] && p[i-1] < p[i] || p[i] <= p[i-1] && p[i-1] < p[i-2]){
                count++;
            }
        }
        println(count);
    } main {
        int n = nextInt();

        int[] p = new int[n];
        p[0] = nextInt();
        p[1] = nextInt();
        int count = 0;
        for(int i=2; i<n; i++){
            p[i] = nextInt();
            if(p[i-2] <= p[i-1] && p[i-1] < p[i] || p[i] <= p[i-1] && p[i-1] < p[i-2]){
                count++;
            }
        }
        println(count);
    } int n = nextInt(); n nextInt() nextInt int[] p = new int[n]; p new int[n] n p[0] = nextInt() p[0] p 0 nextInt() nextInt p[1] = nextInt() p[1] p 1 nextInt() nextInt int count = 0; count 0 for(int i=2; i<n; i++){
            p[i] = nextInt();
            if(p[i-2] <= p[i-1] && p[i-1] < p[i] || p[i] <= p[i-1] && p[i-1] < p[i-2]){
                count++;
            }
        } int i=2; int i=2; i 2 i<n i n i++ i++ i {
            p[i] = nextInt();
            if(p[i-2] <= p[i-1] && p[i-1] < p[i] || p[i] <= p[i-1] && p[i-1] < p[i-2]){
                count++;
            }
        } {
            p[i] = nextInt();
            if(p[i-2] <= p[i-1] && p[i-1] < p[i] || p[i] <= p[i-1] && p[i-1] < p[i-2]){
                count++;
            }
        } p[i] = nextInt() p[i] p i nextInt() nextInt if(p[i-2] <= p[i-1] && p[i-1] < p[i] || p[i] <= p[i-1] && p[i-1] < p[i-2]){
                count++;
            } p[i-2] <= p[i-1] && p[i-1] < p[i] || p[i] <= p[i-1] && p[i-1] < p[i-2] p[i-2] <= p[i-1] && p[i-1] < p[i] p[i-2] <= p[i-1] p[i-2] p i-2 i 2 p[i-1] p i-1 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-1] < p[i-2] p[i] <= p[i-1] p[i] p i p[i-1] p i-1 i 1 p[i-1] < p[i-2] p[i-1] p i-1 i 1 p[i-2] p i-2 i 2 {
                count++;
            } count++ count println(count) println count String[] args args static int nextInt() {
        return Integer.parseInt(next());
    } nextInt {
        return Integer.parseInt(next());
    } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next static Long nextLong() {
        return Long.parseLong(next());
    } nextLong {
        return Long.parseLong(next());
    } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next static String next() {
        return sc.next();
    } next {
        return sc.next();
    } return sc.next(); sc.next() sc.next sc static String nextLine(){
        return sc.nextLine();
    } nextLine {
        return sc.nextLine();
    } return sc.nextLine(); sc.nextLine() sc.nextLine sc static void println(Object o) {
        out.println(o);
        out.flush();
    } println {
        out.println(o);
        out.flush();
    } out.println(o) out.println out o out.flush() out.flush out Object o o static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    } print {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    } PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) out.print(o) out.print out o out.flush() out.flush out Object o o public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = nextInt();

        int[] p = new int[n];
        p[0] = nextInt();
        p[1] = nextInt();
        int count = 0;
        for(int i=2; i<n; i++){
            p[i] = nextInt();
            if(p[i-2] <= p[i-1] && p[i-1] < p[i] || p[i] <= p[i-1] && p[i-1] < p[i-2]){
                count++;
            }
        }
        println(count);
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
} public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = nextInt();

        int[] p = new int[n];
        p[0] = nextInt();
        p[1] = nextInt();
        int count = 0;
        for(int i=2; i<n; i++){
            p[i] = nextInt();
            if(p[i-2] <= p[i-1] && p[i-1] < p[i] || p[i] <= p[i-1] && p[i-1] < p[i-2]){
                count++;
            }
        }
        println(count);
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
} Main
import javax.print.DocFlavor;
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = nextInt();

        int[] p = new int[n];
        p[0] = nextInt();
        p[1] = nextInt();
        int count = 0;
        for(int i=2; i<n; i++){
            p[i] = nextInt();
            if(p[i-2] <= p[i-1] && p[i-1] < p[i] || p[i] <= p[i-1] && p[i-1] < p[i-2]){
                count++;
            }
        }
        println(count);
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}
