import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int p1 = sc.nextInt(), p2 = sc.nextInt(), p3 = 0;
        int cnt = 0;
        
        for (int i = 1; i < n - 1; i++) {
            p3 = sc.nextInt();
            //System.out.println(p1 + ", " + p2 + ", " + p3);
            
            if ((p1 < p2 && p2 < p3) || (p3 < p2 && p2 < p1)) {
                cnt++;
            }
            p1 = p2;
            p2 = p3;
        }
        System.out.println(cnt);
    }
} import java.util.*; util.* java import java.lang.*; lang.* java public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int p1 = sc.nextInt(), p2 = sc.nextInt(), p3 = 0;
        int cnt = 0;
        
        for (int i = 1; i < n - 1; i++) {
            p3 = sc.nextInt();
            //System.out.println(p1 + ", " + p2 + ", " + p3);
            
            if ((p1 < p2 && p2 < p3) || (p3 < p2 && p2 < p1)) {
                cnt++;
            }
            p1 = p2;
            p2 = p3;
        }
        System.out.println(cnt);
    }
} Main public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int p1 = sc.nextInt(), p2 = sc.nextInt(), p3 = 0;
        int cnt = 0;
        
        for (int i = 1; i < n - 1; i++) {
            p3 = sc.nextInt();
            //System.out.println(p1 + ", " + p2 + ", " + p3);
            
            if ((p1 < p2 && p2 < p3) || (p3 < p2 && p2 < p1)) {
                cnt++;
            }
            p1 = p2;
            p2 = p3;
        }
        System.out.println(cnt);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int p1 = sc.nextInt(), p2 = sc.nextInt(), p3 = 0;
        int cnt = 0;
        
        for (int i = 1; i < n - 1; i++) {
            p3 = sc.nextInt();
            //System.out.println(p1 + ", " + p2 + ", " + p3);
            
            if ((p1 < p2 && p2 < p3) || (p3 < p2 && p2 < p1)) {
                cnt++;
            }
            p1 = p2;
            p2 = p3;
        }
        System.out.println(cnt);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] p = new int[n]; p new int[n] n int p1 = sc.nextInt() p1 sc.nextInt() sc.nextInt sc p2 = sc.nextInt() p2 sc.nextInt() sc.nextInt sc p3 = 0; p3 0 int cnt = 0; cnt 0 for (int i = 1; i < n - 1; i++) {
            p3 = sc.nextInt();
            //System.out.println(p1 + ", " + p2 + ", " + p3);
            
            if ((p1 < p2 && p2 < p3) || (p3 < p2 && p2 < p1)) {
                cnt++;
            }
            p1 = p2;
            p2 = p3;
        } int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i {
            p3 = sc.nextInt();
            //System.out.println(p1 + ", " + p2 + ", " + p3);
            
            if ((p1 < p2 && p2 < p3) || (p3 < p2 && p2 < p1)) {
                cnt++;
            }
            p1 = p2;
            p2 = p3;
        } {
            p3 = sc.nextInt();
            //System.out.println(p1 + ", " + p2 + ", " + p3);
            
            if ((p1 < p2 && p2 < p3) || (p3 < p2 && p2 < p1)) {
                cnt++;
            }
            p1 = p2;
            p2 = p3;
        } p3 = sc.nextInt() p3 sc.nextInt() sc.nextInt sc if ((p1 < p2 && p2 < p3) || (p3 < p2 && p2 < p1)) {
                cnt++;
            } (p1 < p2 && p2 < p3) || (p3 < p2 && p2 < p1) (p1 < p2 && p2 < p3) p1 < p2 p1 p2 p2 < p3 p2 p3 (p3 < p2 && p2 < p1) p3 < p2 p3 p2 p2 < p1 p2 p1 {
                cnt++;
            } cnt++ cnt p1 = p2 p1 p2 p2 = p3 p2 p3 System.out.println(cnt) System.out.println System.out System System.out cnt String args[] args public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int p1 = sc.nextInt(), p2 = sc.nextInt(), p3 = 0;
        int cnt = 0;
        
        for (int i = 1; i < n - 1; i++) {
            p3 = sc.nextInt();
            //System.out.println(p1 + ", " + p2 + ", " + p3);
            
            if ((p1 < p2 && p2 < p3) || (p3 < p2 && p2 < p1)) {
                cnt++;
            }
            p1 = p2;
            p2 = p3;
        }
        System.out.println(cnt);
    }
} public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int p1 = sc.nextInt(), p2 = sc.nextInt(), p3 = 0;
        int cnt = 0;
        
        for (int i = 1; i < n - 1; i++) {
            p3 = sc.nextInt();
            //System.out.println(p1 + ", " + p2 + ", " + p3);
            
            if ((p1 < p2 && p2 < p3) || (p3 < p2 && p2 < p1)) {
                cnt++;
            }
            p1 = p2;
            p2 = p3;
        }
        System.out.println(cnt);
    }
} Main
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int p1 = sc.nextInt(), p2 = sc.nextInt(), p3 = 0;
        int cnt = 0;
        
        for (int i = 1; i < n - 1; i++) {
            p3 = sc.nextInt();
            //System.out.println(p1 + ", " + p2 + ", " + p3);
            
            if ((p1 < p2 && p2 < p3) || (p3 < p2 && p2 < p1)) {
                cnt++;
            }
            p1 = p2;
            p2 = p3;
        }
        System.out.println(cnt);
    }
}
