import java.util.Scanner;
import java.util.TreeSet;
public class Main{
    public static void main(String[] args) {
        TreeSet <Integer> numerosUtiles = new TreeSet<>();
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int [] numbers = new int [n];
        for (int i = 0; i < n; i++) {
            numbers[i] = in.nextInt();
            
        }
        for (int i = 1; i < (n-1); i++) {
            int a = numbers[i-1];
            int b = numbers[i];
            int c = numbers[i+1];
            if ((b>a && b<c) || (b<a && b>c)){
                numerosUtiles.add(b);
            }
        }
        System.out.println(numerosUtiles.size());
    }
      
} import java.util.Scanner; Scanner java.util import java.util.TreeSet; TreeSet java.util public class Main{
    public static void main(String[] args) {
        TreeSet <Integer> numerosUtiles = new TreeSet<>();
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int [] numbers = new int [n];
        for (int i = 0; i < n; i++) {
            numbers[i] = in.nextInt();
            
        }
        for (int i = 1; i < (n-1); i++) {
            int a = numbers[i-1];
            int b = numbers[i];
            int c = numbers[i+1];
            if ((b>a && b<c) || (b<a && b>c)){
                numerosUtiles.add(b);
            }
        }
        System.out.println(numerosUtiles.size());
    }
      
} Main public static void main(String[] args) {
        TreeSet <Integer> numerosUtiles = new TreeSet<>();
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int [] numbers = new int [n];
        for (int i = 0; i < n; i++) {
            numbers[i] = in.nextInt();
            
        }
        for (int i = 1; i < (n-1); i++) {
            int a = numbers[i-1];
            int b = numbers[i];
            int c = numbers[i+1];
            if ((b>a && b<c) || (b<a && b>c)){
                numerosUtiles.add(b);
            }
        }
        System.out.println(numerosUtiles.size());
    } main {
        TreeSet <Integer> numerosUtiles = new TreeSet<>();
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int [] numbers = new int [n];
        for (int i = 0; i < n; i++) {
            numbers[i] = in.nextInt();
            
        }
        for (int i = 1; i < (n-1); i++) {
            int a = numbers[i-1];
            int b = numbers[i];
            int c = numbers[i+1];
            if ((b>a && b<c) || (b<a && b>c)){
                numerosUtiles.add(b);
            }
        }
        System.out.println(numerosUtiles.size());
    } TreeSet <Integer> numerosUtiles = new TreeSet<>(); numerosUtiles new TreeSet<>() Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int [] numbers = new int [n]; numbers new int [n] n for (int i = 0; i < n; i++) {
            numbers[i] = in.nextInt();
            
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            numbers[i] = in.nextInt();
            
        } {
            numbers[i] = in.nextInt();
            
        } numbers[i] = in.nextInt() numbers[i] numbers i in.nextInt() in.nextInt in for (int i = 1; i < (n-1); i++) {
            int a = numbers[i-1];
            int b = numbers[i];
            int c = numbers[i+1];
            if ((b>a && b<c) || (b<a && b>c)){
                numerosUtiles.add(b);
            }
        } int i = 1; int i = 1; i 1 i < (n-1) i (n-1) n 1 i++ i++ i {
            int a = numbers[i-1];
            int b = numbers[i];
            int c = numbers[i+1];
            if ((b>a && b<c) || (b<a && b>c)){
                numerosUtiles.add(b);
            }
        } {
            int a = numbers[i-1];
            int b = numbers[i];
            int c = numbers[i+1];
            if ((b>a && b<c) || (b<a && b>c)){
                numerosUtiles.add(b);
            }
        } int a = numbers[i-1]; a numbers[i-1] numbers i-1 i 1 int b = numbers[i]; b numbers[i] numbers i int c = numbers[i+1]; c numbers[i+1] numbers i+1 i 1 if ((b>a && b<c) || (b<a && b>c)){
                numerosUtiles.add(b);
            } (b>a && b<c) || (b<a && b>c) (b>a && b<c) b>a b a b<c b c (b<a && b>c) b<a b a b>c b c {
                numerosUtiles.add(b);
            } numerosUtiles.add(b) numerosUtiles.add numerosUtiles b System.out.println(numerosUtiles.size()) System.out.println System.out System System.out numerosUtiles.size() numerosUtiles.size numerosUtiles String[] args args public class Main{
    public static void main(String[] args) {
        TreeSet <Integer> numerosUtiles = new TreeSet<>();
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int [] numbers = new int [n];
        for (int i = 0; i < n; i++) {
            numbers[i] = in.nextInt();
            
        }
        for (int i = 1; i < (n-1); i++) {
            int a = numbers[i-1];
            int b = numbers[i];
            int c = numbers[i+1];
            if ((b>a && b<c) || (b<a && b>c)){
                numerosUtiles.add(b);
            }
        }
        System.out.println(numerosUtiles.size());
    }
      
} public class Main{
    public static void main(String[] args) {
        TreeSet <Integer> numerosUtiles = new TreeSet<>();
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int [] numbers = new int [n];
        for (int i = 0; i < n; i++) {
            numbers[i] = in.nextInt();
            
        }
        for (int i = 1; i < (n-1); i++) {
            int a = numbers[i-1];
            int b = numbers[i];
            int c = numbers[i+1];
            if ((b>a && b<c) || (b<a && b>c)){
                numerosUtiles.add(b);
            }
        }
        System.out.println(numerosUtiles.size());
    }
      
} Main
import java.util.Scanner;
import java.util.TreeSet;
public class Main{
    public static void main(String[] args) {
        TreeSet <Integer> numerosUtiles = new TreeSet<>();
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int [] numbers = new int [n];
        for (int i = 0; i < n; i++) {
            numbers[i] = in.nextInt();
            
        }
        for (int i = 1; i < (n-1); i++) {
            int a = numbers[i-1];
            int b = numbers[i];
            int c = numbers[i+1];
            if ((b>a && b<c) || (b<a && b>c)){
                numerosUtiles.add(b);
            }
        }
        System.out.println(numerosUtiles.size());
    }
      
}