import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
        int nam[] = new int[n];
        int count = 0;
      
      for(int i = 0 ;i < n ;i++){
       nam[i] =  in.nextInt();
      }
      
      for(int i = 1;i < n-1;i++){
        if(nam[i-1]>nam[i]&&nam[i]>nam[i+1]){count++;}
        else if(nam[i-1]<nam[i]&&nam[i]<nam[i+1]){count++;}
      }
      
      System.out.print(count);
      
	}
} import java.util.*; util.* java public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
        int nam[] = new int[n];
        int count = 0;
      
      for(int i = 0 ;i < n ;i++){
       nam[i] =  in.nextInt();
      }
      
      for(int i = 1;i < n-1;i++){
        if(nam[i-1]>nam[i]&&nam[i]>nam[i+1]){count++;}
        else if(nam[i-1]<nam[i]&&nam[i]<nam[i+1]){count++;}
      }
      
      System.out.print(count);
      
	}
} Main public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
        int nam[] = new int[n];
        int count = 0;
      
      for(int i = 0 ;i < n ;i++){
       nam[i] =  in.nextInt();
      }
      
      for(int i = 1;i < n-1;i++){
        if(nam[i-1]>nam[i]&&nam[i]>nam[i+1]){count++;}
        else if(nam[i-1]<nam[i]&&nam[i]<nam[i+1]){count++;}
      }
      
      System.out.print(count);
      
	} main {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
        int nam[] = new int[n];
        int count = 0;
      
      for(int i = 0 ;i < n ;i++){
       nam[i] =  in.nextInt();
      }
      
      for(int i = 1;i < n-1;i++){
        if(nam[i-1]>nam[i]&&nam[i]>nam[i+1]){count++;}
        else if(nam[i-1]<nam[i]&&nam[i]<nam[i+1]){count++;}
      }
      
      System.out.print(count);
      
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int nam[] = new int[n]; nam new int[n] n int count = 0; count 0 for(int i = 0 ;i < n ;i++){
       nam[i] =  in.nextInt();
      } int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
       nam[i] =  in.nextInt();
      } {
       nam[i] =  in.nextInt();
      } nam[i] =  in.nextInt() nam[i] nam i in.nextInt() in.nextInt in for(int i = 1;i < n-1;i++){
        if(nam[i-1]>nam[i]&&nam[i]>nam[i+1]){count++;}
        else if(nam[i-1]<nam[i]&&nam[i]<nam[i+1]){count++;}
      } int i = 1; int i = 1; i 1 i < n-1 i n-1 n 1 i++ i++ i {
        if(nam[i-1]>nam[i]&&nam[i]>nam[i+1]){count++;}
        else if(nam[i-1]<nam[i]&&nam[i]<nam[i+1]){count++;}
      } {
        if(nam[i-1]>nam[i]&&nam[i]>nam[i+1]){count++;}
        else if(nam[i-1]<nam[i]&&nam[i]<nam[i+1]){count++;}
      } if(nam[i-1]>nam[i]&&nam[i]>nam[i+1]){count++;}
        else if(nam[i-1]<nam[i]&&nam[i]<nam[i+1]){count++;} nam[i-1]>nam[i]&&nam[i]>nam[i+1] nam[i-1]>nam[i] nam[i-1] nam i-1 i 1 nam[i] nam i nam[i]>nam[i+1] nam[i] nam i nam[i+1] nam i+1 i 1 {count++;} count++ count if(nam[i-1]<nam[i]&&nam[i]<nam[i+1]){count++;} nam[i-1]<nam[i]&&nam[i]<nam[i+1] nam[i-1]<nam[i] nam[i-1] nam i-1 i 1 nam[i] nam i nam[i]<nam[i+1] nam[i] nam i nam[i+1] nam i+1 i 1 {count++;} count++ count System.out.print(count) System.out.print System.out System System.out count String[] args args public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
        int nam[] = new int[n];
        int count = 0;
      
      for(int i = 0 ;i < n ;i++){
       nam[i] =  in.nextInt();
      }
      
      for(int i = 1;i < n-1;i++){
        if(nam[i-1]>nam[i]&&nam[i]>nam[i+1]){count++;}
        else if(nam[i-1]<nam[i]&&nam[i]<nam[i+1]){count++;}
      }
      
      System.out.print(count);
      
	}
} public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
        int nam[] = new int[n];
        int count = 0;
      
      for(int i = 0 ;i < n ;i++){
       nam[i] =  in.nextInt();
      }
      
      for(int i = 1;i < n-1;i++){
        if(nam[i-1]>nam[i]&&nam[i]>nam[i+1]){count++;}
        else if(nam[i-1]<nam[i]&&nam[i]<nam[i+1]){count++;}
      }
      
      System.out.print(count);
      
	}
} Main
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
        int nam[] = new int[n];
        int count = 0;
      
      for(int i = 0 ;i < n ;i++){
       nam[i] =  in.nextInt();
      }
      
      for(int i = 1;i < n-1;i++){
        if(nam[i-1]>nam[i]&&nam[i]>nam[i+1]){count++;}
        else if(nam[i-1]<nam[i]&&nam[i]<nam[i+1]){count++;}
      }
      
      System.out.print(count);
      
	}
}