import java.util.Scanner; public class Main_yukicoder116 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } int ret = 0; for (int i = 1; i <= n - 2; i++) { if (isKadomatu(a, i)) { ret++; } } System.out.println(ret); sc.close(); } private static boolean isKadomatu(int[] a, int i) { if (a[i - 1] == a[i] || a[i] == a[i + 1] || a[i - 1] == a[i + 1]) { return false; } if (a[i] > a[i - 1] && a[i] > a[i + 1]) { return true; } if (a[i] < a[i - 1] && a[i] < a[i + 1]) { return true; } return false; } }