import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    String str = sc.nextLine();
    List<String> strList = Arrays.asList(str.split(" "));
    List<List<Integer>> list = new ArrayList<List<Integer>>();
    for(int i = 0; i < n - 2; i++){
      	List<Integer> tmp = new ArrayList<Integer>();
      	tmp.add(Integer.parseInt(strList.get(i)));
      	tmp.add(Integer.parseInt(strList.get(i+1)));
      	tmp.add(Integer.parseInt(strList.get(i+2)));
      	list.add(tmp);
    }
    int count = 0;
    for(int i = 0; i < list.size(); i++){
      List<Integer> tmp = list.get(i);
      if(test(tmp, tmp.get(1)) == true){
        count++;
      }
    }
    System.out.print(count);
  }
  public static boolean test(List<Integer> list, int secondElem){
  	boolean ret = false;
    Collections.sort(list);
    if(list.get(1) == secondElem){
      if(list.get(1) != list.get(0) && list.get(1) != list.get(2)){
	    ret = true;
      }
    }
    return ret;
  }
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz