
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			long[] p = new long[n];
			for (int i = 0; i < n; i++) {
				p[i] = sc.nextLong();
			}
			int result = 0;

			for (int i = 1; i < n - 1; i++) {
				if (judge(p[i - 1], p[i], p[i + 1])) {
					result++;
				}
			}

			System.out.println(result);
		}

	}

	private static boolean judge(long a, long b, long c) {
		return (a < b && b < c) || (c < b && b < a);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			long[] p = new long[n];
			for (int i = 0; i < n; i++) {
				p[i] = sc.nextLong();
			}
			int result = 0;

			for (int i = 1; i < n - 1; i++) {
				if (judge(p[i - 1], p[i], p[i + 1])) {
					result++;
				}
			}

			System.out.println(result);
		}

	}

	private static boolean judge(long a, long b, long c) {
		return (a < b && b < c) || (c < b && b < a);
	}
} Main public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			long[] p = new long[n];
			for (int i = 0; i < n; i++) {
				p[i] = sc.nextLong();
			}
			int result = 0;

			for (int i = 1; i < n - 1; i++) {
				if (judge(p[i - 1], p[i], p[i + 1])) {
					result++;
				}
			}

			System.out.println(result);
		}

	} main {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			long[] p = new long[n];
			for (int i = 0; i < n; i++) {
				p[i] = sc.nextLong();
			}
			int result = 0;

			for (int i = 1; i < n - 1; i++) {
				if (judge(p[i - 1], p[i], p[i + 1])) {
					result++;
				}
			}

			System.out.println(result);
		}

	} try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			long[] p = new long[n];
			for (int i = 0; i < n; i++) {
				p[i] = sc.nextLong();
			}
			int result = 0;

			for (int i = 1; i < n - 1; i++) {
				if (judge(p[i - 1], p[i], p[i + 1])) {
					result++;
				}
			}

			System.out.println(result);
		} {
			int n = sc.nextInt();
			long[] p = new long[n];
			for (int i = 0; i < n; i++) {
				p[i] = sc.nextLong();
			}
			int result = 0;

			for (int i = 1; i < n - 1; i++) {
				if (judge(p[i - 1], p[i], p[i + 1])) {
					result++;
				}
			}

			System.out.println(result);
		} Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc long[] p = new long[n]; p new long[n] n for (int i = 0; i < n; i++) {
				p[i] = sc.nextLong();
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				p[i] = sc.nextLong();
			} {
				p[i] = sc.nextLong();
			} p[i] = sc.nextLong() p[i] p i sc.nextLong() sc.nextLong sc int result = 0; result 0 for (int i = 1; i < n - 1; i++) {
				if (judge(p[i - 1], p[i], p[i + 1])) {
					result++;
				}
			} int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i {
				if (judge(p[i - 1], p[i], p[i + 1])) {
					result++;
				}
			} {
				if (judge(p[i - 1], p[i], p[i + 1])) {
					result++;
				}
			} if (judge(p[i - 1], p[i], p[i + 1])) {
					result++;
				} judge(p[i - 1], p[i], p[i + 1]) judge p[i - 1] p i - 1 i 1 p[i] p i p[i + 1] p i + 1 i 1 {
					result++;
				} result++ result System.out.println(result) System.out.println System.out System System.out result String[] args args private static boolean judge(long a, long b, long c) {
		return (a < b && b < c) || (c < b && b < a);
	} judge {
		return (a < b && b < c) || (c < b && b < a);
	} return (a < b && b < c) || (c < b && b < a); (a < b && b < c) || (c < b && b < a) (a < b && b < c) a < b a b b < c b c (c < b && b < a) c < b c b b < a b a long a a long b b long c c public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			long[] p = new long[n];
			for (int i = 0; i < n; i++) {
				p[i] = sc.nextLong();
			}
			int result = 0;

			for (int i = 1; i < n - 1; i++) {
				if (judge(p[i - 1], p[i], p[i + 1])) {
					result++;
				}
			}

			System.out.println(result);
		}

	}

	private static boolean judge(long a, long b, long c) {
		return (a < b && b < c) || (c < b && b < a);
	}
} public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			long[] p = new long[n];
			for (int i = 0; i < n; i++) {
				p[i] = sc.nextLong();
			}
			int result = 0;

			for (int i = 1; i < n - 1; i++) {
				if (judge(p[i - 1], p[i], p[i + 1])) {
					result++;
				}
			}

			System.out.println(result);
		}

	}

	private static boolean judge(long a, long b, long c) {
		return (a < b && b < c) || (c < b && b < a);
	}
} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			long[] p = new long[n];
			for (int i = 0; i < n; i++) {
				p[i] = sc.nextLong();
			}
			int result = 0;

			for (int i = 1; i < n - 1; i++) {
				if (judge(p[i - 1], p[i], p[i + 1])) {
					result++;
				}
			}

			System.out.println(result);
		}

	}

	private static boolean judge(long a, long b, long c) {
		return (a < b && b < c) || (c < b && b < a);
	}
}
