import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int num = sc.nextInt();
      int[] array = new int[num];
      int count = 0;
      for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      }
      for(int j = 1;j < array.length-1;j++){
      	if((array[j-1] < array[j] && array[j] < array[j+1])||(array[j-1] > array[j] && array[j] > array[j+1])){
        count++;
        }
      }
      System.out.println(count);
    }
} import java.util.*; util.* java public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int num = sc.nextInt();
      int[] array = new int[num];
      int count = 0;
      for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      }
      for(int j = 1;j < array.length-1;j++){
      	if((array[j-1] < array[j] && array[j] < array[j+1])||(array[j-1] > array[j] && array[j] > array[j+1])){
        count++;
        }
      }
      System.out.println(count);
    }
} Main public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int num = sc.nextInt();
      int[] array = new int[num];
      int count = 0;
      for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      }
      for(int j = 1;j < array.length-1;j++){
      	if((array[j-1] < array[j] && array[j] < array[j+1])||(array[j-1] > array[j] && array[j] > array[j+1])){
        count++;
        }
      }
      System.out.println(count);
    } main {
    	Scanner sc = new Scanner(System.in);
      int num = sc.nextInt();
      int[] array = new int[num];
      int count = 0;
      for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      }
      for(int j = 1;j < array.length-1;j++){
      	if((array[j-1] < array[j] && array[j] < array[j+1])||(array[j-1] > array[j] && array[j] > array[j+1])){
        count++;
        }
      }
      System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int num = sc.nextInt(); num sc.nextInt() sc.nextInt sc int[] array = new int[num]; array new int[num] num int count = 0; count 0 for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      } int i = 0; int i = 0; i 0 i < array.length i array.length array array.length i++ i++ i {
      	array[i] = sc.nextInt();
      } {
      	array[i] = sc.nextInt();
      } array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc for(int j = 1;j < array.length-1;j++){
      	if((array[j-1] < array[j] && array[j] < array[j+1])||(array[j-1] > array[j] && array[j] > array[j+1])){
        count++;
        }
      } int j = 1; int j = 1; j 1 j < array.length-1 j array.length-1 array.length array array.length 1 j++ j++ j {
      	if((array[j-1] < array[j] && array[j] < array[j+1])||(array[j-1] > array[j] && array[j] > array[j+1])){
        count++;
        }
      } {
      	if((array[j-1] < array[j] && array[j] < array[j+1])||(array[j-1] > array[j] && array[j] > array[j+1])){
        count++;
        }
      } if((array[j-1] < array[j] && array[j] < array[j+1])||(array[j-1] > array[j] && array[j] > array[j+1])){
        count++;
        } (array[j-1] < array[j] && array[j] < array[j+1])||(array[j-1] > array[j] && array[j] > array[j+1]) (array[j-1] < array[j] && array[j] < array[j+1]) array[j-1] < array[j] array[j-1] array j-1 j 1 array[j] array j array[j] < array[j+1] array[j] array j array[j+1] array j+1 j 1 (array[j-1] > array[j] && array[j] > array[j+1]) array[j-1] > array[j] array[j-1] array j-1 j 1 array[j] array j array[j] > array[j+1] array[j] array j array[j+1] array j+1 j 1 {
        count++;
        } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int num = sc.nextInt();
      int[] array = new int[num];
      int count = 0;
      for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      }
      for(int j = 1;j < array.length-1;j++){
      	if((array[j-1] < array[j] && array[j] < array[j+1])||(array[j-1] > array[j] && array[j] > array[j+1])){
        count++;
        }
      }
      System.out.println(count);
    }
} public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int num = sc.nextInt();
      int[] array = new int[num];
      int count = 0;
      for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      }
      for(int j = 1;j < array.length-1;j++){
      	if((array[j-1] < array[j] && array[j] < array[j+1])||(array[j-1] > array[j] && array[j] > array[j+1])){
        count++;
        }
      }
      System.out.println(count);
    }
} Main
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int num = sc.nextInt();
      int[] array = new int[num];
      int count = 0;
      for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      }
      for(int j = 1;j < array.length-1;j++){
      	if((array[j-1] < array[j] && array[j] < array[j+1])||(array[j-1] > array[j] && array[j] > array[j+1])){
        count++;
        }
      }
      System.out.println(count);
    }
}
