import java.util.*;

public class Main{
	public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      int n = scan.nextInt();
      int[] nums = new int[n];
      int cnt = 0;
      for( int i = 0 ; i < n ; i++ ){
        nums[i] = scan.nextInt();
      }
      for( int i = 1 ; i < n-1 ; i++ ){
        if(
          (nums[i] != Math.max(nums[i],nums[i+1])) && 
          (nums[i] != Math.min(nums[i-1],nums[i])) ||
          (nums[i] != Math.max(nums[i-1],nums[i])) && 
          (nums[i] != Math.min(nums[i],nums[i+1]))     ) cnt++ ;
      }
      System.out.println(cnt);
    }
} import java.util.*; util.* java public class Main{
	public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      int n = scan.nextInt();
      int[] nums = new int[n];
      int cnt = 0;
      for( int i = 0 ; i < n ; i++ ){
        nums[i] = scan.nextInt();
      }
      for( int i = 1 ; i < n-1 ; i++ ){
        if(
          (nums[i] != Math.max(nums[i],nums[i+1])) && 
          (nums[i] != Math.min(nums[i-1],nums[i])) ||
          (nums[i] != Math.max(nums[i-1],nums[i])) && 
          (nums[i] != Math.min(nums[i],nums[i+1]))     ) cnt++ ;
      }
      System.out.println(cnt);
    }
} Main public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      int n = scan.nextInt();
      int[] nums = new int[n];
      int cnt = 0;
      for( int i = 0 ; i < n ; i++ ){
        nums[i] = scan.nextInt();
      }
      for( int i = 1 ; i < n-1 ; i++ ){
        if(
          (nums[i] != Math.max(nums[i],nums[i+1])) && 
          (nums[i] != Math.min(nums[i-1],nums[i])) ||
          (nums[i] != Math.max(nums[i-1],nums[i])) && 
          (nums[i] != Math.min(nums[i],nums[i+1]))     ) cnt++ ;
      }
      System.out.println(cnt);
    } main {
      Scanner scan = new Scanner(System.in);
      int n = scan.nextInt();
      int[] nums = new int[n];
      int cnt = 0;
      for( int i = 0 ; i < n ; i++ ){
        nums[i] = scan.nextInt();
      }
      for( int i = 1 ; i < n-1 ; i++ ){
        if(
          (nums[i] != Math.max(nums[i],nums[i+1])) && 
          (nums[i] != Math.min(nums[i-1],nums[i])) ||
          (nums[i] != Math.max(nums[i-1],nums[i])) && 
          (nums[i] != Math.min(nums[i],nums[i+1]))     ) cnt++ ;
      }
      System.out.println(cnt);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] nums = new int[n]; nums new int[n] n int cnt = 0; cnt 0 for( int i = 0 ; i < n ; i++ ){
        nums[i] = scan.nextInt();
      } int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
        nums[i] = scan.nextInt();
      } {
        nums[i] = scan.nextInt();
      } nums[i] = scan.nextInt() nums[i] nums i scan.nextInt() scan.nextInt scan for( int i = 1 ; i < n-1 ; i++ ){
        if(
          (nums[i] != Math.max(nums[i],nums[i+1])) && 
          (nums[i] != Math.min(nums[i-1],nums[i])) ||
          (nums[i] != Math.max(nums[i-1],nums[i])) && 
          (nums[i] != Math.min(nums[i],nums[i+1]))     ) cnt++ ;
      } int i = 1 ; int i = 1 ; i 1 i < n-1 i n-1 n 1 i++ i++ i {
        if(
          (nums[i] != Math.max(nums[i],nums[i+1])) && 
          (nums[i] != Math.min(nums[i-1],nums[i])) ||
          (nums[i] != Math.max(nums[i-1],nums[i])) && 
          (nums[i] != Math.min(nums[i],nums[i+1]))     ) cnt++ ;
      } {
        if(
          (nums[i] != Math.max(nums[i],nums[i+1])) && 
          (nums[i] != Math.min(nums[i-1],nums[i])) ||
          (nums[i] != Math.max(nums[i-1],nums[i])) && 
          (nums[i] != Math.min(nums[i],nums[i+1]))     ) cnt++ ;
      } if(
          (nums[i] != Math.max(nums[i],nums[i+1])) && 
          (nums[i] != Math.min(nums[i-1],nums[i])) ||
          (nums[i] != Math.max(nums[i-1],nums[i])) && 
          (nums[i] != Math.min(nums[i],nums[i+1]))     ) cnt++ ; (nums[i] != Math.max(nums[i],nums[i+1])) && 
          (nums[i] != Math.min(nums[i-1],nums[i])) ||
          (nums[i] != Math.max(nums[i-1],nums[i])) && 
          (nums[i] != Math.min(nums[i],nums[i+1])) (nums[i] != Math.max(nums[i],nums[i+1])) && 
          (nums[i] != Math.min(nums[i-1],nums[i])) (nums[i] != Math.max(nums[i],nums[i+1])) nums[i] nums i Math.max(nums[i],nums[i+1]) Math.max Math nums[i] nums i nums[i+1] nums i+1 i 1 (nums[i] != Math.min(nums[i-1],nums[i])) nums[i] nums i Math.min(nums[i-1],nums[i]) Math.min Math nums[i-1] nums i-1 i 1 nums[i] nums i (nums[i] != Math.max(nums[i-1],nums[i])) && 
          (nums[i] != Math.min(nums[i],nums[i+1])) (nums[i] != Math.max(nums[i-1],nums[i])) nums[i] nums i Math.max(nums[i-1],nums[i]) Math.max Math nums[i-1] nums i-1 i 1 nums[i] nums i (nums[i] != Math.min(nums[i],nums[i+1])) nums[i] nums i Math.min(nums[i],nums[i+1]) Math.min Math nums[i] nums i nums[i+1] nums i+1 i 1 cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String args[] args public class Main{
	public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      int n = scan.nextInt();
      int[] nums = new int[n];
      int cnt = 0;
      for( int i = 0 ; i < n ; i++ ){
        nums[i] = scan.nextInt();
      }
      for( int i = 1 ; i < n-1 ; i++ ){
        if(
          (nums[i] != Math.max(nums[i],nums[i+1])) && 
          (nums[i] != Math.min(nums[i-1],nums[i])) ||
          (nums[i] != Math.max(nums[i-1],nums[i])) && 
          (nums[i] != Math.min(nums[i],nums[i+1]))     ) cnt++ ;
      }
      System.out.println(cnt);
    }
} public class Main{
	public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      int n = scan.nextInt();
      int[] nums = new int[n];
      int cnt = 0;
      for( int i = 0 ; i < n ; i++ ){
        nums[i] = scan.nextInt();
      }
      for( int i = 1 ; i < n-1 ; i++ ){
        if(
          (nums[i] != Math.max(nums[i],nums[i+1])) && 
          (nums[i] != Math.min(nums[i-1],nums[i])) ||
          (nums[i] != Math.max(nums[i-1],nums[i])) && 
          (nums[i] != Math.min(nums[i],nums[i+1]))     ) cnt++ ;
      }
      System.out.println(cnt);
    }
} Main
import java.util.*;

public class Main{
	public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      int n = scan.nextInt();
      int[] nums = new int[n];
      int cnt = 0;
      for( int i = 0 ; i < n ; i++ ){
        nums[i] = scan.nextInt();
      }
      for( int i = 1 ; i < n-1 ; i++ ){
        if(
          (nums[i] != Math.max(nums[i],nums[i+1])) && 
          (nums[i] != Math.min(nums[i-1],nums[i])) ||
          (nums[i] != Math.max(nums[i-1],nums[i])) && 
          (nums[i] != Math.min(nums[i],nums[i+1]))     ) cnt++ ;
      }
      System.out.println(cnt);
    }
}