import java.util.*;

public class Main {

    public static void main(String[] args) {
        //
        //Compute c1=new Compute();//計算系
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        int answer = 0;
        //String answer="No";
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int p[]=new int[n];

        for (int i=0;i<n;++i) { p[i]=sc.nextInt(); }

        for (int i=1;i<n-1;++i)
        {
            int a=Math.min(p[i-1],p[i+1]);
            int b=Math.max(p[i-1],p[i+1]);
            if(a<p[i] && b>p[i]){++count;}
        }
        answer=count;

        //出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        System.out.println(answer);
    }
} import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        //
        //Compute c1=new Compute();//計算系
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        int answer = 0;
        //String answer="No";
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int p[]=new int[n];

        for (int i=0;i<n;++i) { p[i]=sc.nextInt(); }

        for (int i=1;i<n-1;++i)
        {
            int a=Math.min(p[i-1],p[i+1]);
            int b=Math.max(p[i-1],p[i+1]);
            if(a<p[i] && b>p[i]){++count;}
        }
        answer=count;

        //出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        System.out.println(answer);
    }
} Main public static void main(String[] args) {
        //
        //Compute c1=new Compute();//計算系
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        int answer = 0;
        //String answer="No";
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int p[]=new int[n];

        for (int i=0;i<n;++i) { p[i]=sc.nextInt(); }

        for (int i=1;i<n-1;++i)
        {
            int a=Math.min(p[i-1],p[i+1]);
            int b=Math.max(p[i-1],p[i+1]);
            if(a<p[i] && b>p[i]){++count;}
        }
        answer=count;

        //出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        System.out.println(answer);
    } main {
        //
        //Compute c1=new Compute();//計算系
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        int answer = 0;
        //String answer="No";
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int p[]=new int[n];

        for (int i=0;i<n;++i) { p[i]=sc.nextInt(); }

        for (int i=1;i<n-1;++i)
        {
            int a=Math.min(p[i-1],p[i+1]);
            int b=Math.max(p[i-1],p[i+1]);
            if(a<p[i] && b>p[i]){++count;}
        }
        answer=count;

        //出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        System.out.println(answer);
    } int count = 0; count 0 boolean sw = false; sw false int max = Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE double dMax = Double.MIN_VALUE; dMax Double.MIN_VALUE Double Double.MIN_VALUE double dMin = Double.MAX_VALUE; dMin Double.MAX_VALUE Double Double.MAX_VALUE int answer = 0; answer 0 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 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 for (int i=1;i<n-1;++i)
        {
            int a=Math.min(p[i-1],p[i+1]);
            int b=Math.max(p[i-1],p[i+1]);
            if(a<p[i] && b>p[i]){++count;}
        } int i=1; int i=1; i 1 i<n-1 i n-1 n 1 ++i ++i i {
            int a=Math.min(p[i-1],p[i+1]);
            int b=Math.max(p[i-1],p[i+1]);
            if(a<p[i] && b>p[i]){++count;}
        } {
            int a=Math.min(p[i-1],p[i+1]);
            int b=Math.max(p[i-1],p[i+1]);
            if(a<p[i] && b>p[i]){++count;}
        } int a=Math.min(p[i-1],p[i+1]); a Math.min(p[i-1],p[i+1]) Math.min Math p[i-1] p i-1 i 1 p[i+1] p i+1 i 1 int b=Math.max(p[i-1],p[i+1]); b Math.max(p[i-1],p[i+1]) Math.max Math p[i-1] p i-1 i 1 p[i+1] p i+1 i 1 if(a<p[i] && b>p[i]){++count;} a<p[i] && b>p[i] a<p[i] a p[i] p i b>p[i] b p[i] p i {++count;} ++count count answer=count answer count System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {

    public static void main(String[] args) {
        //
        //Compute c1=new Compute();//計算系
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        int answer = 0;
        //String answer="No";
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int p[]=new int[n];

        for (int i=0;i<n;++i) { p[i]=sc.nextInt(); }

        for (int i=1;i<n-1;++i)
        {
            int a=Math.min(p[i-1],p[i+1]);
            int b=Math.max(p[i-1],p[i+1]);
            if(a<p[i] && b>p[i]){++count;}
        }
        answer=count;

        //出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        System.out.println(answer);
    }
} public class Main {

    public static void main(String[] args) {
        //
        //Compute c1=new Compute();//計算系
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        int answer = 0;
        //String answer="No";
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int p[]=new int[n];

        for (int i=0;i<n;++i) { p[i]=sc.nextInt(); }

        for (int i=1;i<n-1;++i)
        {
            int a=Math.min(p[i-1],p[i+1]);
            int b=Math.max(p[i-1],p[i+1]);
            if(a<p[i] && b>p[i]){++count;}
        }
        answer=count;

        //出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        System.out.println(answer);
    }
} Main
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //
        //Compute c1=new Compute();//計算系
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        int answer = 0;
        //String answer="No";
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int p[]=new int[n];

        for (int i=0;i<n;++i) { p[i]=sc.nextInt(); }

        for (int i=1;i<n-1;++i)
        {
            int a=Math.min(p[i-1],p[i+1]);
            int b=Math.max(p[i-1],p[i+1]);
            if(a<p[i] && b>p[i]){++count;}
        }
        answer=count;

        //出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        System.out.println(answer);
    }
}