
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = stdIn.nextInt();
        }
        int count = 0;
        for(int i = 1; i + 1 < n; i++){
            if((p[i - 1] - p[i]) * (p[i + 1] - p[i]) < 0){
                count++;
            }
        }
        System.out.println(count);    
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = stdIn.nextInt();
        }
        int count = 0;
        for(int i = 1; i + 1 < n; i++){
            if((p[i - 1] - p[i]) * (p[i + 1] - p[i]) < 0){
                count++;
            }
        }
        System.out.println(count);    
    }
} Main public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = stdIn.nextInt();
        }
        int count = 0;
        for(int i = 1; i + 1 < n; i++){
            if((p[i - 1] - p[i]) * (p[i + 1] - p[i]) < 0){
                count++;
            }
        }
        System.out.println(count);    
    } main {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = stdIn.nextInt();
        }
        int count = 0;
        for(int i = 1; i + 1 < n; i++){
            if((p[i - 1] - p[i]) * (p[i + 1] - p[i]) < 0){
                count++;
            }
        }
        System.out.println(count);    
    } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int[] p = new int[n]; p new int[n] n for(int i = 0; i < n; i++){
            p[i] = stdIn.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            p[i] = stdIn.nextInt();
        } {
            p[i] = stdIn.nextInt();
        } p[i] = stdIn.nextInt() p[i] p i stdIn.nextInt() stdIn.nextInt stdIn int count = 0; count 0 for(int i = 1; i + 1 < n; i++){
            if((p[i - 1] - p[i]) * (p[i + 1] - p[i]) < 0){
                count++;
            }
        } int i = 1; int i = 1; i 1 i + 1 < n i + 1 i 1 n i++ i++ i {
            if((p[i - 1] - p[i]) * (p[i + 1] - p[i]) < 0){
                count++;
            }
        } {
            if((p[i - 1] - p[i]) * (p[i + 1] - p[i]) < 0){
                count++;
            }
        } if((p[i - 1] - p[i]) * (p[i + 1] - p[i]) < 0){
                count++;
            } (p[i - 1] - p[i]) * (p[i + 1] - p[i]) < 0 (p[i - 1] - p[i]) * (p[i + 1] - p[i]) (p[i - 1] - p[i]) p[i - 1] p i - 1 i 1 p[i] p i (p[i + 1] - p[i]) p[i + 1] p i + 1 i 1 p[i] p i 0 {
                count++;
            } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args

import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = stdIn.nextInt();
        }
        int count = 0;
        for(int i = 1; i + 1 < n; i++){
            if((p[i - 1] - p[i]) * (p[i + 1] - p[i]) < 0){
                count++;
            }
        }
        System.out.println(count);    
    }
}