import java.util.*; public class kadomatsu{ public static void main(String... args){ Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[] k = new int[n]; for(int i = 0; i < n; i++){ k[i] = scan.nextInt(); } System.out.println(search(n,k)); } public static int search(int n,int[] k){ int count=0; for(int i = 0; i < n-2; i++){ int low = k[i]; int middle = k[i+1]; int high = k[i+2]; if((low != middle && middle != high) || (middle < high && middle > low)){ count++; } } return count; } }