import java.io.*; import java.util.*; import java.math.*; class Main { public static void out (Object o) { System.out.println(o); } public static boolean isPd (int a , int b , int c) { if (a == b || a == c || b == c) return false; return (c < a && a < b) || (b < a && a < c) || (a < c && c < b) || (b < c && c < a); } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] a = new int[n]; String[] line = br.readLine().split(" "); for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(line[i]); } int ans = 0; for (int i = 2; i < n; i++) { ans = isPd(a[i - 2] , a[i - 1] , a[i]) ? ans + 1 : ans; } out(ans); } }