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