import java.util.*;
import java.awt.*;

class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = Integer.parseInt(sc.next());
        int[] p = new int[n];
        int ans=0;
        for(int i = 0; i < n; i++){
            p[i] = Integer.parseInt(sc.next());
        }
        for(int i = 1; i < n-1; i++){
            if(p[i-1] < p[i] && p[i] < p[i+1]){
                //System.out.println(p[i]);
                ans++;
            }else if(p[i+1] < p[i] && p[i] < p[i-1]){
                //System.out.println(p[i]);
                ans++;
            }
        }
        System.out.println(ans);
    }
} import java.util.*; util.* java import java.awt.*; awt.* java class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = Integer.parseInt(sc.next());
        int[] p = new int[n];
        int ans=0;
        for(int i = 0; i < n; i++){
            p[i] = Integer.parseInt(sc.next());
        }
        for(int i = 1; i < n-1; i++){
            if(p[i-1] < p[i] && p[i] < p[i+1]){
                //System.out.println(p[i]);
                ans++;
            }else if(p[i+1] < p[i] && p[i] < p[i-1]){
                //System.out.println(p[i]);
                ans++;
            }
        }
        System.out.println(ans);
    }
} Main private static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
        int n = Integer.parseInt(sc.next());
        int[] p = new int[n];
        int ans=0;
        for(int i = 0; i < n; i++){
            p[i] = Integer.parseInt(sc.next());
        }
        for(int i = 1; i < n-1; i++){
            if(p[i-1] < p[i] && p[i] < p[i+1]){
                //System.out.println(p[i]);
                ans++;
            }else if(p[i+1] < p[i] && p[i] < p[i-1]){
                //System.out.println(p[i]);
                ans++;
            }
        }
        System.out.println(ans);
    } main {
        int n = Integer.parseInt(sc.next());
        int[] p = new int[n];
        int ans=0;
        for(int i = 0; i < n; i++){
            p[i] = Integer.parseInt(sc.next());
        }
        for(int i = 1; i < n-1; i++){
            if(p[i-1] < p[i] && p[i] < p[i+1]){
                //System.out.println(p[i]);
                ans++;
            }else if(p[i+1] < p[i] && p[i] < p[i-1]){
                //System.out.println(p[i]);
                ans++;
            }
        }
        System.out.println(ans);
    } int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] p = new int[n]; p new int[n] n int ans=0; ans 0 for(int i = 0; i < n; i++){
            p[i] = Integer.parseInt(sc.next());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            p[i] = Integer.parseInt(sc.next());
        } {
            p[i] = Integer.parseInt(sc.next());
        } p[i] = Integer.parseInt(sc.next()) p[i] p i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc for(int i = 1; i < n-1; i++){
            if(p[i-1] < p[i] && p[i] < p[i+1]){
                //System.out.println(p[i]);
                ans++;
            }else if(p[i+1] < p[i] && p[i] < p[i-1]){
                //System.out.println(p[i]);
                ans++;
            }
        } 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]){
                //System.out.println(p[i]);
                ans++;
            }else if(p[i+1] < p[i] && p[i] < p[i-1]){
                //System.out.println(p[i]);
                ans++;
            }
        } {
            if(p[i-1] < p[i] && p[i] < p[i+1]){
                //System.out.println(p[i]);
                ans++;
            }else if(p[i+1] < p[i] && p[i] < p[i-1]){
                //System.out.println(p[i]);
                ans++;
            }
        } if(p[i-1] < p[i] && p[i] < p[i+1]){
                //System.out.println(p[i]);
                ans++;
            }else if(p[i+1] < p[i] && p[i] < p[i-1]){
                //System.out.println(p[i]);
                ans++;
            } 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 {
                //System.out.println(p[i]);
                ans++;
            } ans++ ans if(p[i+1] < p[i] && p[i] < p[i-1]){
                //System.out.println(p[i]);
                ans++;
            } 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 {
                //System.out.println(p[i]);
                ans++;
            } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args
import java.util.*;
import java.awt.*;

class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = Integer.parseInt(sc.next());
        int[] p = new int[n];
        int ans=0;
        for(int i = 0; i < n; i++){
            p[i] = Integer.parseInt(sc.next());
        }
        for(int i = 1; i < n-1; i++){
            if(p[i-1] < p[i] && p[i] < p[i+1]){
                //System.out.println(p[i]);
                ans++;
            }else if(p[i+1] < p[i] && p[i] < p[i-1]){
                //System.out.println(p[i]);
                ans++;
            }
        }
        System.out.println(ans);
    }
}
