import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 0;
		int[] array = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(sc.next());
			if (i == 0 || i == 1) {
				continue;
			}
			int a = array[i - 2];
			int b = array[i - 1];
			int c = array[i];
			if (a == b && b == c) {
				continue;
			}
			int diff = (a - b) * (b - c);
			if (diff >= 0) {
				ans++;
			}
		}
		sc.close();
		System.out.println(ans);
	}
} 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 ans = 0;
		int[] array = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(sc.next());
			if (i == 0 || i == 1) {
				continue;
			}
			int a = array[i - 2];
			int b = array[i - 1];
			int c = array[i];
			if (a == b && b == c) {
				continue;
			}
			int diff = (a - b) * (b - c);
			if (diff >= 0) {
				ans++;
			}
		}
		sc.close();
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 0;
		int[] array = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(sc.next());
			if (i == 0 || i == 1) {
				continue;
			}
			int a = array[i - 2];
			int b = array[i - 1];
			int c = array[i];
			if (a == b && b == c) {
				continue;
			}
			int diff = (a - b) * (b - c);
			if (diff >= 0) {
				ans++;
			}
		}
		sc.close();
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 0;
		int[] array = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(sc.next());
			if (i == 0 || i == 1) {
				continue;
			}
			int a = array[i - 2];
			int b = array[i - 1];
			int c = array[i];
			if (a == b && b == c) {
				continue;
			}
			int diff = (a - b) * (b - c);
			if (diff >= 0) {
				ans++;
			}
		}
		sc.close();
		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int ans = 0; ans 0 int[] array = new int[N]; array new int[N] N for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(sc.next());
			if (i == 0 || i == 1) {
				continue;
			}
			int a = array[i - 2];
			int b = array[i - 1];
			int c = array[i];
			if (a == b && b == c) {
				continue;
			}
			int diff = (a - b) * (b - c);
			if (diff >= 0) {
				ans++;
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			array[i] = Integer.parseInt(sc.next());
			if (i == 0 || i == 1) {
				continue;
			}
			int a = array[i - 2];
			int b = array[i - 1];
			int c = array[i];
			if (a == b && b == c) {
				continue;
			}
			int diff = (a - b) * (b - c);
			if (diff >= 0) {
				ans++;
			}
		} {
			array[i] = Integer.parseInt(sc.next());
			if (i == 0 || i == 1) {
				continue;
			}
			int a = array[i - 2];
			int b = array[i - 1];
			int c = array[i];
			if (a == b && b == c) {
				continue;
			}
			int diff = (a - b) * (b - c);
			if (diff >= 0) {
				ans++;
			}
		} array[i] = Integer.parseInt(sc.next()) array[i] array i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if (i == 0 || i == 1) {
				continue;
			} i == 0 || i == 1 i == 0 i 0 i == 1 i 1 {
				continue;
			} continue; int a = array[i - 2]; a array[i - 2] array i - 2 i 2 int b = array[i - 1]; b array[i - 1] array i - 1 i 1 int c = array[i]; c array[i] array i if (a == b && b == c) {
				continue;
			} a == b && b == c a == b a b b == c b c {
				continue;
			} continue; int diff = (a - b) * (b - c); diff (a - b) * (b - c) (a - b) a b (b - c) b c if (diff >= 0) {
				ans++;
			} diff >= 0 diff 0 {
				ans++;
			} ans++ ans sc.close() sc.close sc System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 0;
		int[] array = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(sc.next());
			if (i == 0 || i == 1) {
				continue;
			}
			int a = array[i - 2];
			int b = array[i - 1];
			int c = array[i];
			if (a == b && b == c) {
				continue;
			}
			int diff = (a - b) * (b - c);
			if (diff >= 0) {
				ans++;
			}
		}
		sc.close();
		System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 0;
		int[] array = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(sc.next());
			if (i == 0 || i == 1) {
				continue;
			}
			int a = array[i - 2];
			int b = array[i - 1];
			int c = array[i];
			if (a == b && b == c) {
				continue;
			}
			int diff = (a - b) * (b - c);
			if (diff >= 0) {
				ans++;
			}
		}
		sc.close();
		System.out.println(ans);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 0;
		int[] array = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = Integer.parseInt(sc.next());
			if (i == 0 || i == 1) {
				continue;
			}
			int a = array[i - 2];
			int b = array[i - 1];
			int c = array[i];
			if (a == b && b == c) {
				continue;
			}
			int diff = (a - b) * (b - c);
			if (diff >= 0) {
				ans++;
			}
		}
		sc.close();
		System.out.println(ans);
	}
}