import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int lst[] = new int[n];
        int ans = 0;
        for(int i = 0; i < n; i++){
            lst[i] = Integer.parseInt(scan.next());
        }
        for(int i = 0; i < n-2; i++){
            if((lst[i+1]<lst[i]&&lst[i+2]<lst[i+1])||(lst[i+1]>lst[i]&&lst[i+2]>lst[i+1])){
                ans++;
            }
        }
        System.out.println(ans);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int lst[] = new int[n];
        int ans = 0;
        for(int i = 0; i < n; i++){
            lst[i] = Integer.parseInt(scan.next());
        }
        for(int i = 0; i < n-2; i++){
            if((lst[i+1]<lst[i]&&lst[i+2]<lst[i+1])||(lst[i+1]>lst[i]&&lst[i+2]>lst[i+1])){
                ans++;
            }
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int lst[] = new int[n];
        int ans = 0;
        for(int i = 0; i < n; i++){
            lst[i] = Integer.parseInt(scan.next());
        }
        for(int i = 0; i < n-2; i++){
            if((lst[i+1]<lst[i]&&lst[i+2]<lst[i+1])||(lst[i+1]>lst[i]&&lst[i+2]>lst[i+1])){
                ans++;
            }
        }
        System.out.println(ans);
    } main {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int lst[] = new int[n];
        int ans = 0;
        for(int i = 0; i < n; i++){
            lst[i] = Integer.parseInt(scan.next());
        }
        for(int i = 0; i < n-2; i++){
            if((lst[i+1]<lst[i]&&lst[i+2]<lst[i+1])||(lst[i+1]>lst[i]&&lst[i+2]>lst[i+1])){
                ans++;
            }
        }
        System.out.println(ans);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = Integer.parseInt(scan.next()); n Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan int lst[] = new int[n]; lst new int[n] n int ans = 0; ans 0 for(int i = 0; i < n; i++){
            lst[i] = Integer.parseInt(scan.next());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            lst[i] = Integer.parseInt(scan.next());
        } {
            lst[i] = Integer.parseInt(scan.next());
        } lst[i] = Integer.parseInt(scan.next()) lst[i] lst i Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan for(int i = 0; i < n-2; i++){
            if((lst[i+1]<lst[i]&&lst[i+2]<lst[i+1])||(lst[i+1]>lst[i]&&lst[i+2]>lst[i+1])){
                ans++;
            }
        } int i = 0; int i = 0; i 0 i < n-2 i n-2 n 2 i++ i++ i {
            if((lst[i+1]<lst[i]&&lst[i+2]<lst[i+1])||(lst[i+1]>lst[i]&&lst[i+2]>lst[i+1])){
                ans++;
            }
        } {
            if((lst[i+1]<lst[i]&&lst[i+2]<lst[i+1])||(lst[i+1]>lst[i]&&lst[i+2]>lst[i+1])){
                ans++;
            }
        } if((lst[i+1]<lst[i]&&lst[i+2]<lst[i+1])||(lst[i+1]>lst[i]&&lst[i+2]>lst[i+1])){
                ans++;
            } (lst[i+1]<lst[i]&&lst[i+2]<lst[i+1])||(lst[i+1]>lst[i]&&lst[i+2]>lst[i+1]) (lst[i+1]<lst[i]&&lst[i+2]<lst[i+1]) lst[i+1]<lst[i] lst[i+1] lst i+1 i 1 lst[i] lst i lst[i+2]<lst[i+1] lst[i+2] lst i+2 i 2 lst[i+1] lst i+1 i 1 (lst[i+1]>lst[i]&&lst[i+2]>lst[i+1]) lst[i+1]>lst[i] lst[i+1] lst i+1 i 1 lst[i] lst i lst[i+2]>lst[i+1] lst[i+2] lst i+2 i 2 lst[i+1] lst i+1 i 1 {
                ans++;
            } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int lst[] = new int[n];
        int ans = 0;
        for(int i = 0; i < n; i++){
            lst[i] = Integer.parseInt(scan.next());
        }
        for(int i = 0; i < n-2; i++){
            if((lst[i+1]<lst[i]&&lst[i+2]<lst[i+1])||(lst[i+1]>lst[i]&&lst[i+2]>lst[i+1])){
                ans++;
            }
        }
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int lst[] = new int[n];
        int ans = 0;
        for(int i = 0; i < n; i++){
            lst[i] = Integer.parseInt(scan.next());
        }
        for(int i = 0; i < n-2; i++){
            if((lst[i+1]<lst[i]&&lst[i+2]<lst[i+1])||(lst[i+1]>lst[i]&&lst[i+2]>lst[i+1])){
                ans++;
            }
        }
        System.out.println(ans);
    }
} Main
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int lst[] = new int[n];
        int ans = 0;
        for(int i = 0; i < n; i++){
            lst[i] = Integer.parseInt(scan.next());
        }
        for(int i = 0; i < n-2; i++){
            if((lst[i+1]<lst[i]&&lst[i+2]<lst[i+1])||(lst[i+1]>lst[i]&&lst[i+2]>lst[i+1])){
                ans++;
            }
        }
        System.out.println(ans);
    }
}