import java.util.Scanner;

public class Main {
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		int length = sc.nextInt();

		int argment[] = new int[length];

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

		sc.close();

		int cnt = 0;

		for(int i = 0;i < length - 2;i++) {
			cnt += (
						(argment[i + 1] <= argment[i + 2] && argment[i + 1] >= argment[i]) ||
						(argment[i + 1] >= argment[i + 2] && argment[i + 1] <= argment[i])
					) ? 1 : 0;
		}

		System.out.println(cnt);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		int length = sc.nextInt();

		int argment[] = new int[length];

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

		sc.close();

		int cnt = 0;

		for(int i = 0;i < length - 2;i++) {
			cnt += (
						(argment[i + 1] <= argment[i + 2] && argment[i + 1] >= argment[i]) ||
						(argment[i + 1] >= argment[i + 2] && argment[i + 1] <= argment[i])
					) ? 1 : 0;
		}

		System.out.println(cnt);
	}
} Main public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		int length = sc.nextInt();

		int argment[] = new int[length];

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

		sc.close();

		int cnt = 0;

		for(int i = 0;i < length - 2;i++) {
			cnt += (
						(argment[i + 1] <= argment[i + 2] && argment[i + 1] >= argment[i]) ||
						(argment[i + 1] >= argment[i + 2] && argment[i + 1] <= argment[i])
					) ? 1 : 0;
		}

		System.out.println(cnt);
	} main {

		Scanner sc = new Scanner(System.in);

		int length = sc.nextInt();

		int argment[] = new int[length];

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

		sc.close();

		int cnt = 0;

		for(int i = 0;i < length - 2;i++) {
			cnt += (
						(argment[i + 1] <= argment[i + 2] && argment[i + 1] >= argment[i]) ||
						(argment[i + 1] >= argment[i + 2] && argment[i + 1] <= argment[i])
					) ? 1 : 0;
		}

		System.out.println(cnt);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int length = sc.nextInt(); length sc.nextInt() sc.nextInt sc int argment[] = new int[length]; argment new int[length] length for(int i = 0;i < length;i++) {
			argment[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < length i length i++ i++ i {
			argment[i] = sc.nextInt();
		} {
			argment[i] = sc.nextInt();
		} argment[i] = sc.nextInt() argment[i] argment i sc.nextInt() sc.nextInt sc sc.close() sc.close sc int cnt = 0; cnt 0 for(int i = 0;i < length - 2;i++) {
			cnt += (
						(argment[i + 1] <= argment[i + 2] && argment[i + 1] >= argment[i]) ||
						(argment[i + 1] >= argment[i + 2] && argment[i + 1] <= argment[i])
					) ? 1 : 0;
		} int i = 0; int i = 0; i 0 i < length - 2 i length - 2 length 2 i++ i++ i {
			cnt += (
						(argment[i + 1] <= argment[i + 2] && argment[i + 1] >= argment[i]) ||
						(argment[i + 1] >= argment[i + 2] && argment[i + 1] <= argment[i])
					) ? 1 : 0;
		} {
			cnt += (
						(argment[i + 1] <= argment[i + 2] && argment[i + 1] >= argment[i]) ||
						(argment[i + 1] >= argment[i + 2] && argment[i + 1] <= argment[i])
					) ? 1 : 0;
		} cnt += (
						(argment[i + 1] <= argment[i + 2] && argment[i + 1] >= argment[i]) ||
						(argment[i + 1] >= argment[i + 2] && argment[i + 1] <= argment[i])
					) ? 1 : 0 cnt (
						(argment[i + 1] <= argment[i + 2] && argment[i + 1] >= argment[i]) ||
						(argment[i + 1] >= argment[i + 2] && argment[i + 1] <= argment[i])
					) ? 1 : 0 (
						(argment[i + 1] <= argment[i + 2] && argment[i + 1] >= argment[i]) ||
						(argment[i + 1] >= argment[i + 2] && argment[i + 1] <= argment[i])
					) (argment[i + 1] <= argment[i + 2] && argment[i + 1] >= argment[i]) argment[i + 1] <= argment[i + 2] argment[i + 1] argment i + 1 i 1 argment[i + 2] argment i + 2 i 2 argment[i + 1] >= argment[i] argment[i + 1] argment i + 1 i 1 argment[i] argment i (argment[i + 1] >= argment[i + 2] && argment[i + 1] <= argment[i]) argment[i + 1] >= argment[i + 2] argment[i + 1] argment i + 1 i 1 argment[i + 2] argment i + 2 i 2 argment[i + 1] <= argment[i] argment[i + 1] argment i + 1 i 1 argment[i] argment i 1 0 System.out.println(cnt) System.out.println System.out System System.out cnt String args[] args public class Main {
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		int length = sc.nextInt();

		int argment[] = new int[length];

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

		sc.close();

		int cnt = 0;

		for(int i = 0;i < length - 2;i++) {
			cnt += (
						(argment[i + 1] <= argment[i + 2] && argment[i + 1] >= argment[i]) ||
						(argment[i + 1] >= argment[i + 2] && argment[i + 1] <= argment[i])
					) ? 1 : 0;
		}

		System.out.println(cnt);
	}
} public class Main {
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		int length = sc.nextInt();

		int argment[] = new int[length];

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

		sc.close();

		int cnt = 0;

		for(int i = 0;i < length - 2;i++) {
			cnt += (
						(argment[i + 1] <= argment[i + 2] && argment[i + 1] >= argment[i]) ||
						(argment[i + 1] >= argment[i + 2] && argment[i + 1] <= argment[i])
					) ? 1 : 0;
		}

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

public class Main {
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		int length = sc.nextInt();

		int argment[] = new int[length];

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

		sc.close();

		int cnt = 0;

		for(int i = 0;i < length - 2;i++) {
			cnt += (
						(argment[i + 1] <= argment[i + 2] && argment[i + 1] >= argment[i]) ||
						(argment[i + 1] >= argment[i + 2] && argment[i + 1] <= argment[i])
					) ? 1 : 0;
		}

		System.out.println(cnt);
	}
}
