// package app;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long u = sc.nextLong();
        // long D = sc.nextLong();
        // long K = sc.nextLong();

        long[] p = new long[(int)u];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextLong();
        }

        int cnt = 0;
        for (int i = 1; i < p.length - 1; i++) {
            
            long[] tmp = Arrays.copyOfRange(p, i-1, i + 2);
            Arrays.sort(tmp);
            if(tmp[1] == p[i]) cnt++; 
        }

        System.out.println(cnt);
    }
} import java.math.BigDecimal; BigDecimal java.math import java.util.Arrays; Arrays java.util import java.util.HashMap; HashMap java.util import java.util.Map; Map java.util import java.util.Objects; Objects java.util import java.util.Scanner; Scanner java.util import java.util.StringJoiner; StringJoiner java.util import java.util.stream.Stream; Stream java.util.stream public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long u = sc.nextLong();
        // long D = sc.nextLong();
        // long K = sc.nextLong();

        long[] p = new long[(int)u];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextLong();
        }

        int cnt = 0;
        for (int i = 1; i < p.length - 1; i++) {
            
            long[] tmp = Arrays.copyOfRange(p, i-1, i + 2);
            Arrays.sort(tmp);
            if(tmp[1] == p[i]) cnt++; 
        }

        System.out.println(cnt);
    }
} Main public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long u = sc.nextLong();
        // long D = sc.nextLong();
        // long K = sc.nextLong();

        long[] p = new long[(int)u];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextLong();
        }

        int cnt = 0;
        for (int i = 1; i < p.length - 1; i++) {
            
            long[] tmp = Arrays.copyOfRange(p, i-1, i + 2);
            Arrays.sort(tmp);
            if(tmp[1] == p[i]) cnt++; 
        }

        System.out.println(cnt);
    } main {

        Scanner sc = new Scanner(System.in);

        long u = sc.nextLong();
        // long D = sc.nextLong();
        // long K = sc.nextLong();

        long[] p = new long[(int)u];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextLong();
        }

        int cnt = 0;
        for (int i = 1; i < p.length - 1; i++) {
            
            long[] tmp = Arrays.copyOfRange(p, i-1, i + 2);
            Arrays.sort(tmp);
            if(tmp[1] == p[i]) cnt++; 
        }

        System.out.println(cnt);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long u = sc.nextLong(); u sc.nextLong() sc.nextLong sc long[] p = new long[(int)u]; p new long[(int)u] (int)u for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextLong();
        } int i = 0; int i = 0; i 0 i < p.length i p.length p p.length i++ i++ i {
            p[i] = sc.nextLong();
        } {
            p[i] = sc.nextLong();
        } p[i] = sc.nextLong() p[i] p i sc.nextLong() sc.nextLong sc int cnt = 0; cnt 0 for (int i = 1; i < p.length - 1; i++) {
            
            long[] tmp = Arrays.copyOfRange(p, i-1, i + 2);
            Arrays.sort(tmp);
            if(tmp[1] == p[i]) cnt++; 
        } int i = 1; int i = 1; i 1 i < p.length - 1 i p.length - 1 p.length p p.length 1 i++ i++ i {
            
            long[] tmp = Arrays.copyOfRange(p, i-1, i + 2);
            Arrays.sort(tmp);
            if(tmp[1] == p[i]) cnt++; 
        } {
            
            long[] tmp = Arrays.copyOfRange(p, i-1, i + 2);
            Arrays.sort(tmp);
            if(tmp[1] == p[i]) cnt++; 
        } long[] tmp = Arrays.copyOfRange(p, i-1, i + 2); tmp Arrays.copyOfRange(p, i-1, i + 2) Arrays.copyOfRange Arrays p i-1 i 1 i + 2 i 2 Arrays.sort(tmp) Arrays.sort Arrays tmp if(tmp[1] == p[i]) cnt++; tmp[1] == p[i] tmp[1] tmp 1 p[i] p i cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt final String[] args args public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long u = sc.nextLong();
        // long D = sc.nextLong();
        // long K = sc.nextLong();

        long[] p = new long[(int)u];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextLong();
        }

        int cnt = 0;
        for (int i = 1; i < p.length - 1; i++) {
            
            long[] tmp = Arrays.copyOfRange(p, i-1, i + 2);
            Arrays.sort(tmp);
            if(tmp[1] == p[i]) cnt++; 
        }

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

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long u = sc.nextLong();
        // long D = sc.nextLong();
        // long K = sc.nextLong();

        long[] p = new long[(int)u];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextLong();
        }

        int cnt = 0;
        for (int i = 1; i < p.length - 1; i++) {
            
            long[] tmp = Arrays.copyOfRange(p, i-1, i + 2);
            Arrays.sort(tmp);
            if(tmp[1] == p[i]) cnt++; 
        }

        System.out.println(cnt);
    }
} Main
// package app;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long u = sc.nextLong();
        // long D = sc.nextLong();
        // long K = sc.nextLong();

        long[] p = new long[(int)u];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextLong();
        }

        int cnt = 0;
        for (int i = 1; i < p.length - 1; i++) {
            
            long[] tmp = Arrays.copyOfRange(p, i-1, i + 2);
            Arrays.sort(tmp);
            if(tmp[1] == p[i]) cnt++; 
        }

        System.out.println(cnt);
    }
}