import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] p = new int[n];

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

		int cnt = 0;
		for (int i = 1; i < n - 1; i++) {
			if (isBSecond(p[i - 1], p[i], p[i + 1]))
				cnt++;
		}

		System.out.println(cnt);

		sc.close();
	}

	static boolean isBSecond(int a, int b, int c) {
		if (a >= b) {
			if (b >= c) {
				return true;
			}
		} else {
			if (c >= b) {
				return true;
			}
		}

		return false;
	}

} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] p = new int[n];

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

		int cnt = 0;
		for (int i = 1; i < n - 1; i++) {
			if (isBSecond(p[i - 1], p[i], p[i + 1]))
				cnt++;
		}

		System.out.println(cnt);

		sc.close();
	}

	static boolean isBSecond(int a, int b, int c) {
		if (a >= b) {
			if (b >= c) {
				return true;
			}
		} else {
			if (c >= b) {
				return true;
			}
		}

		return false;
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] p = new int[n];

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

		int cnt = 0;
		for (int i = 1; i < n - 1; i++) {
			if (isBSecond(p[i - 1], p[i], p[i + 1]))
				cnt++;
		}

		System.out.println(cnt);

		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] p = new int[n];

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

		int cnt = 0;
		for (int i = 1; i < n - 1; i++) {
			if (isBSecond(p[i - 1], p[i], p[i + 1]))
				cnt++;
		}

		System.out.println(cnt);

		sc.close();
	} 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 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 int cnt = 0; cnt 0 for (int i = 1; i < n - 1; i++) {
			if (isBSecond(p[i - 1], p[i], p[i + 1]))
				cnt++;
		} int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i {
			if (isBSecond(p[i - 1], p[i], p[i + 1]))
				cnt++;
		} {
			if (isBSecond(p[i - 1], p[i], p[i + 1]))
				cnt++;
		} if (isBSecond(p[i - 1], p[i], p[i + 1]))
				cnt++; isBSecond(p[i - 1], p[i], p[i + 1]) isBSecond p[i - 1] p i - 1 i 1 p[i] p i p[i + 1] p i + 1 i 1 cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt sc.close() sc.close sc String[] args args static boolean isBSecond(int a, int b, int c) {
		if (a >= b) {
			if (b >= c) {
				return true;
			}
		} else {
			if (c >= b) {
				return true;
			}
		}

		return false;
	} isBSecond {
		if (a >= b) {
			if (b >= c) {
				return true;
			}
		} else {
			if (c >= b) {
				return true;
			}
		}

		return false;
	} if (a >= b) {
			if (b >= c) {
				return true;
			}
		} else {
			if (c >= b) {
				return true;
			}
		} a >= b a b {
			if (b >= c) {
				return true;
			}
		} if (b >= c) {
				return true;
			} b >= c b c {
				return true;
			} return true; true {
			if (c >= b) {
				return true;
			}
		} if (c >= b) {
				return true;
			} c >= b c b {
				return true;
			} return true; true return false; false int a a int b b int c c
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] p = new int[n];

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

		int cnt = 0;
		for (int i = 1; i < n - 1; i++) {
			if (isBSecond(p[i - 1], p[i], p[i + 1]))
				cnt++;
		}

		System.out.println(cnt);

		sc.close();
	}

	static boolean isBSecond(int a, int b, int c) {
		if (a >= b) {
			if (b >= c) {
				return true;
			}
		} else {
			if (c >= b) {
				return true;
			}
		}

		return false;
	}

}
