import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		int[] tmp = new int[3];
		int answer = 0;

		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		for (int i = 1; i < n - 1; i++) {
			tmp[0] = p[i - 1];
			tmp[1] = p[i];
			tmp[2] = p[i + 1];

			Arrays.sort(tmp);

			if (p[i] == tmp[1]) answer++;
		}

		System.out.println(answer);
	}
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		int[] tmp = new int[3];
		int answer = 0;

		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		for (int i = 1; i < n - 1; i++) {
			tmp[0] = p[i - 1];
			tmp[1] = p[i];
			tmp[2] = p[i + 1];

			Arrays.sort(tmp);

			if (p[i] == tmp[1]) answer++;
		}

		System.out.println(answer);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		int[] tmp = new int[3];
		int answer = 0;

		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		for (int i = 1; i < n - 1; i++) {
			tmp[0] = p[i - 1];
			tmp[1] = p[i];
			tmp[2] = p[i + 1];

			Arrays.sort(tmp);

			if (p[i] == tmp[1]) answer++;
		}

		System.out.println(answer);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		int[] tmp = new int[3];
		int answer = 0;

		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		for (int i = 1; i < n - 1; i++) {
			tmp[0] = p[i - 1];
			tmp[1] = p[i];
			tmp[2] = p[i + 1];

			Arrays.sort(tmp);

			if (p[i] == tmp[1]) answer++;
		}

		System.out.println(answer);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] p = new int[n]; p new int[n] n int[] tmp = new int[3]; tmp new int[3] 3 int answer = 0; answer 0 for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			p[i] = sc.nextInt();
		} {
			p[i] = sc.nextInt();
		} p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc for (int i = 1; i < n - 1; i++) {
			tmp[0] = p[i - 1];
			tmp[1] = p[i];
			tmp[2] = p[i + 1];

			Arrays.sort(tmp);

			if (p[i] == tmp[1]) answer++;
		} int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i {
			tmp[0] = p[i - 1];
			tmp[1] = p[i];
			tmp[2] = p[i + 1];

			Arrays.sort(tmp);

			if (p[i] == tmp[1]) answer++;
		} {
			tmp[0] = p[i - 1];
			tmp[1] = p[i];
			tmp[2] = p[i + 1];

			Arrays.sort(tmp);

			if (p[i] == tmp[1]) answer++;
		} tmp[0] = p[i - 1] tmp[0] tmp 0 p[i - 1] p i - 1 i 1 tmp[1] = p[i] tmp[1] tmp 1 p[i] p i tmp[2] = p[i + 1] tmp[2] tmp 2 p[i + 1] p i + 1 i 1 Arrays.sort(tmp) Arrays.sort Arrays tmp if (p[i] == tmp[1]) answer++; p[i] == tmp[1] p[i] p i tmp[1] tmp 1 answer++ answer System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		int[] tmp = new int[3];
		int answer = 0;

		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		for (int i = 1; i < n - 1; i++) {
			tmp[0] = p[i - 1];
			tmp[1] = p[i];
			tmp[2] = p[i + 1];

			Arrays.sort(tmp);

			if (p[i] == tmp[1]) answer++;
		}

		System.out.println(answer);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		int[] tmp = new int[3];
		int answer = 0;

		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		for (int i = 1; i < n - 1; i++) {
			tmp[0] = p[i - 1];
			tmp[1] = p[i];
			tmp[2] = p[i + 1];

			Arrays.sort(tmp);

			if (p[i] == tmp[1]) answer++;
		}

		System.out.println(answer);
	}
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		int[] tmp = new int[3];
		int answer = 0;

		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		for (int i = 1; i < n - 1; i++) {
			tmp[0] = p[i - 1];
			tmp[1] = p[i];
			tmp[2] = p[i + 1];

			Arrays.sort(tmp);

			if (p[i] == tmp[1]) answer++;
		}

		System.out.println(answer);
	}
}
