								//package Dynamic;
import java.io.*;
import java.util.*;
class Main
{
    static public void main(String[] args) throws IOException 
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        int ar[]=new int[n];
      StringTokenizer st=new StringTokenizer(br.readLine());
//        int a=Integer.parseInt(st.nextToken());
//        int b=Integer.parseInt(st.nextToken());
//        int c=Integer.parseInt(st.nextToken());
        //int d=Integer.parseInt(st.nextToken());
       int i=0;
        while(st.hasMoreTokens())
        {
        	ar[i++]=Integer.parseInt(st.nextToken());
        }
        int c=0;
        for(int x=1;x<n-1;x++)
        {
        	int arr[]=new int[3];
        	arr[0]=ar[x];
        	arr[1]=ar[x-1];
        	arr[2]=ar[x+1];
        	Arrays.sort(arr);
        	if(arr[1]==ar[x])
        		c++;
        }
        System.out.println(c);
//        for(int x=0;x<n;x++)
//        {
//        	
//        }
        
        
    }
} import java.io.*; io.* java import java.util.*; util.* java class Main
{
    static public void main(String[] args) throws IOException 
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        int ar[]=new int[n];
      StringTokenizer st=new StringTokenizer(br.readLine());
//        int a=Integer.parseInt(st.nextToken());
//        int b=Integer.parseInt(st.nextToken());
//        int c=Integer.parseInt(st.nextToken());
        //int d=Integer.parseInt(st.nextToken());
       int i=0;
        while(st.hasMoreTokens())
        {
        	ar[i++]=Integer.parseInt(st.nextToken());
        }
        int c=0;
        for(int x=1;x<n-1;x++)
        {
        	int arr[]=new int[3];
        	arr[0]=ar[x];
        	arr[1]=ar[x-1];
        	arr[2]=ar[x+1];
        	Arrays.sort(arr);
        	if(arr[1]==ar[x])
        		c++;
        }
        System.out.println(c);
//        for(int x=0;x<n;x++)
//        {
//        	
//        }
        
        
    }
} Main static public void main(String[] args) throws IOException 
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        int ar[]=new int[n];
      StringTokenizer st=new StringTokenizer(br.readLine());
//        int a=Integer.parseInt(st.nextToken());
//        int b=Integer.parseInt(st.nextToken());
//        int c=Integer.parseInt(st.nextToken());
        //int d=Integer.parseInt(st.nextToken());
       int i=0;
        while(st.hasMoreTokens())
        {
        	ar[i++]=Integer.parseInt(st.nextToken());
        }
        int c=0;
        for(int x=1;x<n-1;x++)
        {
        	int arr[]=new int[3];
        	arr[0]=ar[x];
        	arr[1]=ar[x-1];
        	arr[2]=ar[x+1];
        	Arrays.sort(arr);
        	if(arr[1]==ar[x])
        		c++;
        }
        System.out.println(c);
//        for(int x=0;x<n;x++)
//        {
//        	
//        }
        
        
    } main {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        int ar[]=new int[n];
      StringTokenizer st=new StringTokenizer(br.readLine());
//        int a=Integer.parseInt(st.nextToken());
//        int b=Integer.parseInt(st.nextToken());
//        int c=Integer.parseInt(st.nextToken());
        //int d=Integer.parseInt(st.nextToken());
       int i=0;
        while(st.hasMoreTokens())
        {
        	ar[i++]=Integer.parseInt(st.nextToken());
        }
        int c=0;
        for(int x=1;x<n-1;x++)
        {
        	int arr[]=new int[3];
        	arr[0]=ar[x];
        	arr[1]=ar[x-1];
        	arr[2]=ar[x+1];
        	Arrays.sort(arr);
        	if(arr[1]==ar[x])
        		c++;
        }
        System.out.println(c);
//        for(int x=0;x<n;x++)
//        {
//        	
//        }
        
        
    } BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n=Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int ar[]=new int[n]; ar new int[n] n StringTokenizer st=new StringTokenizer(br.readLine()); st new StringTokenizer(br.readLine()) int i=0; i 0 while(st.hasMoreTokens())
        {
        	ar[i++]=Integer.parseInt(st.nextToken());
        } st.hasMoreTokens() st.hasMoreTokens st {
        	ar[i++]=Integer.parseInt(st.nextToken());
        } ar[i++]=Integer.parseInt(st.nextToken()) ar[i++] ar i++ i Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int c=0; c 0 for(int x=1;x<n-1;x++)
        {
        	int arr[]=new int[3];
        	arr[0]=ar[x];
        	arr[1]=ar[x-1];
        	arr[2]=ar[x+1];
        	Arrays.sort(arr);
        	if(arr[1]==ar[x])
        		c++;
        } int x=1; int x=1; x 1 x<n-1 x n-1 n 1 x++ x++ x {
        	int arr[]=new int[3];
        	arr[0]=ar[x];
        	arr[1]=ar[x-1];
        	arr[2]=ar[x+1];
        	Arrays.sort(arr);
        	if(arr[1]==ar[x])
        		c++;
        } {
        	int arr[]=new int[3];
        	arr[0]=ar[x];
        	arr[1]=ar[x-1];
        	arr[2]=ar[x+1];
        	Arrays.sort(arr);
        	if(arr[1]==ar[x])
        		c++;
        } int arr[]=new int[3]; arr new int[3] 3 arr[0]=ar[x] arr[0] arr 0 ar[x] ar x arr[1]=ar[x-1] arr[1] arr 1 ar[x-1] ar x-1 x 1 arr[2]=ar[x+1] arr[2] arr 2 ar[x+1] ar x+1 x 1 Arrays.sort(arr) Arrays.sort Arrays arr if(arr[1]==ar[x])
        		c++; arr[1]==ar[x] arr[1] arr 1 ar[x] ar x c++ c System.out.println(c) System.out.println System.out System System.out c String[] args args
								//package Dynamic;
import java.io.*;
import java.util.*;
class Main
{
    static public void main(String[] args) throws IOException 
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        int ar[]=new int[n];
      StringTokenizer st=new StringTokenizer(br.readLine());
//        int a=Integer.parseInt(st.nextToken());
//        int b=Integer.parseInt(st.nextToken());
//        int c=Integer.parseInt(st.nextToken());
        //int d=Integer.parseInt(st.nextToken());
       int i=0;
        while(st.hasMoreTokens())
        {
        	ar[i++]=Integer.parseInt(st.nextToken());
        }
        int c=0;
        for(int x=1;x<n-1;x++)
        {
        	int arr[]=new int[3];
        	arr[0]=ar[x];
        	arr[1]=ar[x-1];
        	arr[2]=ar[x+1];
        	Arrays.sort(arr);
        	if(arr[1]==ar[x])
        		c++;
        }
        System.out.println(c);
//        for(int x=0;x<n;x++)
//        {
//        	
//        }
        
        
    }
}
