//created by Whiplash99
import java.io.*;
import java.util.*;
public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        N=Integer.parseInt(br.readLine().trim());
        String s[]=br.readLine().trim().split(" ");
        int a[]=new int[N];
        for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]);

        int count=0;
        for(i=1;i<N-1;i++)
        {
            if(a[i]<=a[i-1]&&a[i]>=a[i+1]) count++;
            else if(a[i]>=a[i-1]&&a[i]<=a[i+1]) count++;
        }
        System.out.println(count);
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        N=Integer.parseInt(br.readLine().trim());
        String s[]=br.readLine().trim().split(" ");
        int a[]=new int[N];
        for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]);

        int count=0;
        for(i=1;i<N-1;i++)
        {
            if(a[i]<=a[i-1]&&a[i]>=a[i+1]) count++;
            else if(a[i]>=a[i-1]&&a[i]<=a[i+1]) count++;
        }
        System.out.println(count);
    }
} Main public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        N=Integer.parseInt(br.readLine().trim());
        String s[]=br.readLine().trim().split(" ");
        int a[]=new int[N];
        for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]);

        int count=0;
        for(i=1;i<N-1;i++)
        {
            if(a[i]<=a[i-1]&&a[i]>=a[i+1]) count++;
            else if(a[i]>=a[i-1]&&a[i]<=a[i+1]) count++;
        }
        System.out.println(count);
    } main {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        N=Integer.parseInt(br.readLine().trim());
        String s[]=br.readLine().trim().split(" ");
        int a[]=new int[N];
        for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]);

        int count=0;
        for(i=1;i<N-1;i++)
        {
            if(a[i]<=a[i-1]&&a[i]>=a[i+1]) count++;
            else if(a[i]>=a[i-1]&&a[i]<=a[i+1]) count++;
        }
        System.out.println(count);
    } BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int i i N; N N=Integer.parseInt(br.readLine().trim()) N Integer.parseInt(br.readLine().trim()) Integer.parseInt Integer br.readLine().trim() br.readLine().trim br.readLine() br.readLine br String s[]=br.readLine().trim().split(" "); s br.readLine().trim().split(" ") br.readLine().trim().split br.readLine().trim() br.readLine().trim br.readLine() br.readLine br " " int a[]=new int[N]; a new int[N] N for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]); i=0; i=0 i 0 i<N i N i++ i++ i a[i]=Integer.parseInt(s[i]); a[i]=Integer.parseInt(s[i]) a[i] a i Integer.parseInt(s[i]) Integer.parseInt Integer s[i] s i int count=0; count 0 for(i=1;i<N-1;i++)
        {
            if(a[i]<=a[i-1]&&a[i]>=a[i+1]) count++;
            else if(a[i]>=a[i-1]&&a[i]<=a[i+1]) count++;
        } i=1; i=1 i 1 i<N-1 i N-1 N 1 i++ i++ i {
            if(a[i]<=a[i-1]&&a[i]>=a[i+1]) count++;
            else if(a[i]>=a[i-1]&&a[i]<=a[i+1]) count++;
        } {
            if(a[i]<=a[i-1]&&a[i]>=a[i+1]) count++;
            else if(a[i]>=a[i-1]&&a[i]<=a[i+1]) count++;
        } if(a[i]<=a[i-1]&&a[i]>=a[i+1]) count++;
            else if(a[i]>=a[i-1]&&a[i]<=a[i+1]) count++; a[i]<=a[i-1]&&a[i]>=a[i+1] a[i]<=a[i-1] a[i] a i a[i-1] a i-1 i 1 a[i]>=a[i+1] a[i] a i a[i+1] a i+1 i 1 count++ count if(a[i]>=a[i-1]&&a[i]<=a[i+1]) count++; a[i]>=a[i-1]&&a[i]<=a[i+1] a[i]>=a[i-1] a[i] a i a[i-1] a i-1 i 1 a[i]<=a[i+1] a[i] a i a[i+1] a i+1 i 1 count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        N=Integer.parseInt(br.readLine().trim());
        String s[]=br.readLine().trim().split(" ");
        int a[]=new int[N];
        for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]);

        int count=0;
        for(i=1;i<N-1;i++)
        {
            if(a[i]<=a[i-1]&&a[i]>=a[i+1]) count++;
            else if(a[i]>=a[i-1]&&a[i]<=a[i+1]) count++;
        }
        System.out.println(count);
    }
} public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        N=Integer.parseInt(br.readLine().trim());
        String s[]=br.readLine().trim().split(" ");
        int a[]=new int[N];
        for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]);

        int count=0;
        for(i=1;i<N-1;i++)
        {
            if(a[i]<=a[i-1]&&a[i]>=a[i+1]) count++;
            else if(a[i]>=a[i-1]&&a[i]<=a[i+1]) count++;
        }
        System.out.println(count);
    }
} Main
//created by Whiplash99
import java.io.*;
import java.util.*;
public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        N=Integer.parseInt(br.readLine().trim());
        String s[]=br.readLine().trim().split(" ");
        int a[]=new int[N];
        for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]);

        int count=0;
        for(i=1;i<N-1;i++)
        {
            if(a[i]<=a[i-1]&&a[i]>=a[i+1]) count++;
            else if(a[i]>=a[i-1]&&a[i]<=a[i+1]) count++;
        }
        System.out.println(count);
    }
}