import java.util.*;
public class Main {
  	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		int ret = test(n, array);
		System.out.println(ret);
		sc.close();
	}
	static int test(int n, int[] array) {
		int count = 0;
		for (int i = 0; i < n - 2; i++) {
			int p1 = array[i];
			int p2 = array[i + 1];
			int p3 = array[i + 2];
			if ((p1 >= p2 && p2 > p3) || (p3 >= p2 && p2 > p1)) {
				count++;
			}
		}
		return count;
	}
} import java.util.*; util.* java public class Main {
  	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		int ret = test(n, array);
		System.out.println(ret);
		sc.close();
	}
	static int test(int n, int[] array) {
		int count = 0;
		for (int i = 0; i < n - 2; i++) {
			int p1 = array[i];
			int p2 = array[i + 1];
			int p3 = array[i + 2];
			if ((p1 >= p2 && p2 > p3) || (p3 >= p2 && p2 > p1)) {
				count++;
			}
		}
		return count;
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		int ret = test(n, array);
		System.out.println(ret);
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		int ret = test(n, array);
		System.out.println(ret);
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] array = new int[n]; array new int[n] n for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			array[i] = sc.nextInt();
		} {
			array[i] = sc.nextInt();
		} array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc int ret = test(n, array); ret test(n, array) test n array System.out.println(ret) System.out.println System.out System System.out ret sc.close() sc.close sc String[] args args static int test(int n, int[] array) {
		int count = 0;
		for (int i = 0; i < n - 2; i++) {
			int p1 = array[i];
			int p2 = array[i + 1];
			int p3 = array[i + 2];
			if ((p1 >= p2 && p2 > p3) || (p3 >= p2 && p2 > p1)) {
				count++;
			}
		}
		return count;
	} test {
		int count = 0;
		for (int i = 0; i < n - 2; i++) {
			int p1 = array[i];
			int p2 = array[i + 1];
			int p3 = array[i + 2];
			if ((p1 >= p2 && p2 > p3) || (p3 >= p2 && p2 > p1)) {
				count++;
			}
		}
		return count;
	} int count = 0; count 0 for (int i = 0; i < n - 2; i++) {
			int p1 = array[i];
			int p2 = array[i + 1];
			int p3 = array[i + 2];
			if ((p1 >= p2 && p2 > p3) || (p3 >= p2 && p2 > p1)) {
				count++;
			}
		} int i = 0; int i = 0; i 0 i < n - 2 i n - 2 n 2 i++ i++ i {
			int p1 = array[i];
			int p2 = array[i + 1];
			int p3 = array[i + 2];
			if ((p1 >= p2 && p2 > p3) || (p3 >= p2 && p2 > p1)) {
				count++;
			}
		} {
			int p1 = array[i];
			int p2 = array[i + 1];
			int p3 = array[i + 2];
			if ((p1 >= p2 && p2 > p3) || (p3 >= p2 && p2 > p1)) {
				count++;
			}
		} int p1 = array[i]; p1 array[i] array i int p2 = array[i + 1]; p2 array[i + 1] array i + 1 i 1 int p3 = array[i + 2]; p3 array[i + 2] array i + 2 i 2 if ((p1 >= p2 && p2 > p3) || (p3 >= p2 && p2 > p1)) {
				count++;
			} (p1 >= p2 && p2 > p3) || (p3 >= p2 && p2 > p1) (p1 >= p2 && p2 > p3) p1 >= p2 p1 p2 p2 > p3 p2 p3 (p3 >= p2 && p2 > p1) p3 >= p2 p3 p2 p2 > p1 p2 p1 {
				count++;
			} count++ count return count; count int n n int[] array array public class Main {
  	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		int ret = test(n, array);
		System.out.println(ret);
		sc.close();
	}
	static int test(int n, int[] array) {
		int count = 0;
		for (int i = 0; i < n - 2; i++) {
			int p1 = array[i];
			int p2 = array[i + 1];
			int p3 = array[i + 2];
			if ((p1 >= p2 && p2 > p3) || (p3 >= p2 && p2 > p1)) {
				count++;
			}
		}
		return count;
	}
} public class Main {
  	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		int ret = test(n, array);
		System.out.println(ret);
		sc.close();
	}
	static int test(int n, int[] array) {
		int count = 0;
		for (int i = 0; i < n - 2; i++) {
			int p1 = array[i];
			int p2 = array[i + 1];
			int p3 = array[i + 2];
			if ((p1 >= p2 && p2 > p3) || (p3 >= p2 && p2 > p1)) {
				count++;
			}
		}
		return count;
	}
} Main
import java.util.*;
public class Main {
  	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		int ret = test(n, array);
		System.out.println(ret);
		sc.close();
	}
	static int test(int n, int[] array) {
		int count = 0;
		for (int i = 0; i < n - 2; i++) {
			int p1 = array[i];
			int p2 = array[i + 1];
			int p3 = array[i + 2];
			if ((p1 >= p2 && p2 > p3) || (p3 >= p2 && p2 > p1)) {
				count++;
			}
		}
		return count;
	}
}