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

import static java.lang.StrictMath.abs;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n+2];
        int count =0;
        //格納
        for(int i=0; i < n; i++){
            p[i] = sc.nextInt();
        }
        p[n] = p[n-2];
        p[n+1]= p[n-1];

        //判定
        for(int k = 0; k < n;k++){
            if((p[k]>p[k+1] && p[k+1]>= p[k+2] )|| (p[k]<=p[k+1] && p[k+1]< p[k+2])){
                count++;
            }
        }
        //出力
        System.out.println(count);
    }
}
 import java.util.*; util.* java import java.lang.*; lang.* java import static java.lang.StrictMath.abs; import static java.lang.StrictMath.abs; import static java.lang.StrictMath.abs; class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n+2];
        int count =0;
        //格納
        for(int i=0; i < n; i++){
            p[i] = sc.nextInt();
        }
        p[n] = p[n-2];
        p[n+1]= p[n-1];

        //判定
        for(int k = 0; k < n;k++){
            if((p[k]>p[k+1] && p[k+1]>= p[k+2] )|| (p[k]<=p[k+1] && p[k+1]< p[k+2])){
                count++;
            }
        }
        //出力
        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n+2];
        int count =0;
        //格納
        for(int i=0; i < n; i++){
            p[i] = sc.nextInt();
        }
        p[n] = p[n-2];
        p[n+1]= p[n-1];

        //判定
        for(int k = 0; k < n;k++){
            if((p[k]>p[k+1] && p[k+1]>= p[k+2] )|| (p[k]<=p[k+1] && p[k+1]< p[k+2])){
                count++;
            }
        }
        //出力
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n+2];
        int count =0;
        //格納
        for(int i=0; i < n; i++){
            p[i] = sc.nextInt();
        }
        p[n] = p[n-2];
        p[n+1]= p[n-1];

        //判定
        for(int k = 0; k < n;k++){
            if((p[k]>p[k+1] && p[k+1]>= p[k+2] )|| (p[k]<=p[k+1] && p[k+1]< p[k+2])){
                count++;
            }
        }
        //出力
        System.out.println(count);
    } 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+2]; p new int[n+2] n+2 n 2 int count =0; count 0 for(int i=0; i < n; i++){
            p[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i < n i n i++ i++ i {
            p[i] = sc.nextInt();
        } {
            p[i] = sc.nextInt();
        } p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc p[n] = p[n-2] p[n] p n p[n-2] p n-2 n 2 p[n+1]= p[n-1] p[n+1] p n+1 n 1 p[n-1] p n-1 n 1 for(int k = 0; k < n;k++){
            if((p[k]>p[k+1] && p[k+1]>= p[k+2] )|| (p[k]<=p[k+1] && p[k+1]< p[k+2])){
                count++;
            }
        } int k = 0; int k = 0; k 0 k < n k n k++ k++ k {
            if((p[k]>p[k+1] && p[k+1]>= p[k+2] )|| (p[k]<=p[k+1] && p[k+1]< p[k+2])){
                count++;
            }
        } {
            if((p[k]>p[k+1] && p[k+1]>= p[k+2] )|| (p[k]<=p[k+1] && p[k+1]< p[k+2])){
                count++;
            }
        } if((p[k]>p[k+1] && p[k+1]>= p[k+2] )|| (p[k]<=p[k+1] && p[k+1]< p[k+2])){
                count++;
            } (p[k]>p[k+1] && p[k+1]>= p[k+2] )|| (p[k]<=p[k+1] && p[k+1]< p[k+2]) (p[k]>p[k+1] && p[k+1]>= p[k+2] ) p[k]>p[k+1] p[k] p k p[k+1] p k+1 k 1 p[k+1]>= p[k+2] p[k+1] p k+1 k 1 p[k+2] p k+2 k 2 (p[k]<=p[k+1] && p[k+1]< p[k+2]) p[k]<=p[k+1] p[k] p k p[k+1] p k+1 k 1 p[k+1]< p[k+2] p[k+1] p k+1 k 1 p[k+2] p k+2 k 2 {
                count++;
            } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.*;
import java.lang.*;

import static java.lang.StrictMath.abs;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n+2];
        int count =0;
        //格納
        for(int i=0; i < n; i++){
            p[i] = sc.nextInt();
        }
        p[n] = p[n-2];
        p[n+1]= p[n-1];

        //判定
        for(int k = 0; k < n;k++){
            if((p[k]>p[k+1] && p[k+1]>= p[k+2] )|| (p[k]<=p[k+1] && p[k+1]< p[k+2])){
                count++;
            }
        }
        //出力
        System.out.println(count);
    }
}

