import java.util.Scanner;
public class Main{
	public static void main(String[]args){
    	Scanner sc=new Scanner(System.in);
     	int n=sc.nextInt();
      	int total=0;
      	int p[]=new int[n];
      
      	for(int t=0;t<n;t++){
        	p[t]= sc.nextInt();
        }
      	
      	for(int k=0;k<n-2;k++){
        	if(p[k]<p[k+1]){
            	if(p[k+1]<p[k+2]){
                	total+=1;
                }
            }else{
            	if(p[k+2]<p[k+1]){
                	total+=1;
                }
            }
        }
      	
      	System.out.println(total);
      
      
    }
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[]args){
    	Scanner sc=new Scanner(System.in);
     	int n=sc.nextInt();
      	int total=0;
      	int p[]=new int[n];
      
      	for(int t=0;t<n;t++){
        	p[t]= sc.nextInt();
        }
      	
      	for(int k=0;k<n-2;k++){
        	if(p[k]<p[k+1]){
            	if(p[k+1]<p[k+2]){
                	total+=1;
                }
            }else{
            	if(p[k+2]<p[k+1]){
                	total+=1;
                }
            }
        }
      	
      	System.out.println(total);
      
      
    }
} Main public static void main(String[]args){
    	Scanner sc=new Scanner(System.in);
     	int n=sc.nextInt();
      	int total=0;
      	int p[]=new int[n];
      
      	for(int t=0;t<n;t++){
        	p[t]= sc.nextInt();
        }
      	
      	for(int k=0;k<n-2;k++){
        	if(p[k]<p[k+1]){
            	if(p[k+1]<p[k+2]){
                	total+=1;
                }
            }else{
            	if(p[k+2]<p[k+1]){
                	total+=1;
                }
            }
        }
      	
      	System.out.println(total);
      
      
    } main {
    	Scanner sc=new Scanner(System.in);
     	int n=sc.nextInt();
      	int total=0;
      	int p[]=new int[n];
      
      	for(int t=0;t<n;t++){
        	p[t]= sc.nextInt();
        }
      	
      	for(int k=0;k<n-2;k++){
        	if(p[k]<p[k+1]){
            	if(p[k+1]<p[k+2]){
                	total+=1;
                }
            }else{
            	if(p[k+2]<p[k+1]){
                	total+=1;
                }
            }
        }
      	
      	System.out.println(total);
      
      
    } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int total=0; total 0 int p[]=new int[n]; p new int[n] n for(int t=0;t<n;t++){
        	p[t]= sc.nextInt();
        } int t=0; int t=0; t 0 t<n t n t++ t++ t {
        	p[t]= sc.nextInt();
        } {
        	p[t]= sc.nextInt();
        } p[t]= sc.nextInt() p[t] p t sc.nextInt() sc.nextInt sc for(int k=0;k<n-2;k++){
        	if(p[k]<p[k+1]){
            	if(p[k+1]<p[k+2]){
                	total+=1;
                }
            }else{
            	if(p[k+2]<p[k+1]){
                	total+=1;
                }
            }
        } int k=0; int k=0; k 0 k<n-2 k n-2 n 2 k++ k++ k {
        	if(p[k]<p[k+1]){
            	if(p[k+1]<p[k+2]){
                	total+=1;
                }
            }else{
            	if(p[k+2]<p[k+1]){
                	total+=1;
                }
            }
        } {
        	if(p[k]<p[k+1]){
            	if(p[k+1]<p[k+2]){
                	total+=1;
                }
            }else{
            	if(p[k+2]<p[k+1]){
                	total+=1;
                }
            }
        } if(p[k]<p[k+1]){
            	if(p[k+1]<p[k+2]){
                	total+=1;
                }
            }else{
            	if(p[k+2]<p[k+1]){
                	total+=1;
                }
            } p[k]<p[k+1] p[k] p k p[k+1] p k+1 k 1 {
            	if(p[k+1]<p[k+2]){
                	total+=1;
                }
            } if(p[k+1]<p[k+2]){
                	total+=1;
                } p[k+1]<p[k+2] p[k+1] p k+1 k 1 p[k+2] p k+2 k 2 {
                	total+=1;
                } total+=1 total 1 {
            	if(p[k+2]<p[k+1]){
                	total+=1;
                }
            } if(p[k+2]<p[k+1]){
                	total+=1;
                } p[k+2]<p[k+1] p[k+2] p k+2 k 2 p[k+1] p k+1 k 1 {
                	total+=1;
                } total+=1 total 1 System.out.println(total) System.out.println System.out System System.out total String[]args args public class Main{
	public static void main(String[]args){
    	Scanner sc=new Scanner(System.in);
     	int n=sc.nextInt();
      	int total=0;
      	int p[]=new int[n];
      
      	for(int t=0;t<n;t++){
        	p[t]= sc.nextInt();
        }
      	
      	for(int k=0;k<n-2;k++){
        	if(p[k]<p[k+1]){
            	if(p[k+1]<p[k+2]){
                	total+=1;
                }
            }else{
            	if(p[k+2]<p[k+1]){
                	total+=1;
                }
            }
        }
      	
      	System.out.println(total);
      
      
    }
} public class Main{
	public static void main(String[]args){
    	Scanner sc=new Scanner(System.in);
     	int n=sc.nextInt();
      	int total=0;
      	int p[]=new int[n];
      
      	for(int t=0;t<n;t++){
        	p[t]= sc.nextInt();
        }
      	
      	for(int k=0;k<n-2;k++){
        	if(p[k]<p[k+1]){
            	if(p[k+1]<p[k+2]){
                	total+=1;
                }
            }else{
            	if(p[k+2]<p[k+1]){
                	total+=1;
                }
            }
        }
      	
      	System.out.println(total);
      
      
    }
} Main
import java.util.Scanner;
public class Main{
	public static void main(String[]args){
    	Scanner sc=new Scanner(System.in);
     	int n=sc.nextInt();
      	int total=0;
      	int p[]=new int[n];
      
      	for(int t=0;t<n;t++){
        	p[t]= sc.nextInt();
        }
      	
      	for(int k=0;k<n-2;k++){
        	if(p[k]<p[k+1]){
            	if(p[k+1]<p[k+2]){
                	total+=1;
                }
            }else{
            	if(p[k+2]<p[k+1]){
                	total+=1;
                }
            }
        }
      	
      	System.out.println(total);
      
      
    }
}