import java.util.Scanner;

public class Main {
	static int r = 0;
	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();
		}
		sc.close();
		int r = 0;
		for(int i = 1; i < N - 1; i++) {
			int min = Math.min(Math.min(p[i - 1], p[i]), p[i + 1]);
			int max = Math.max(Math.max(p[i - 1], p[i]), p[i + 1]);
			if(min < p[i] && p[i] < max) r++;
		}
		System.out.println(r);
	}
}	 import java.util.Scanner; Scanner java.util public class Main {
	static int r = 0;
	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();
		}
		sc.close();
		int r = 0;
		for(int i = 1; i < N - 1; i++) {
			int min = Math.min(Math.min(p[i - 1], p[i]), p[i + 1]);
			int max = Math.max(Math.max(p[i - 1], p[i]), p[i + 1]);
			if(min < p[i] && p[i] < max) r++;
		}
		System.out.println(r);
	}
} Main static int r = 0; r 0 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();
		}
		sc.close();
		int r = 0;
		for(int i = 1; i < N - 1; i++) {
			int min = Math.min(Math.min(p[i - 1], p[i]), p[i + 1]);
			int max = Math.max(Math.max(p[i - 1], p[i]), p[i + 1]);
			if(min < p[i] && p[i] < max) r++;
		}
		System.out.println(r);
	} 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();
		}
		sc.close();
		int r = 0;
		for(int i = 1; i < N - 1; i++) {
			int min = Math.min(Math.min(p[i - 1], p[i]), p[i + 1]);
			int max = Math.max(Math.max(p[i - 1], p[i]), p[i + 1]);
			if(min < p[i] && p[i] < max) r++;
		}
		System.out.println(r);
	} 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 sc.close() sc.close sc int r = 0; r 0 for(int i = 1; i < N - 1; i++) {
			int min = Math.min(Math.min(p[i - 1], p[i]), p[i + 1]);
			int max = Math.max(Math.max(p[i - 1], p[i]), p[i + 1]);
			if(min < p[i] && p[i] < max) r++;
		} int i = 1; int i = 1; i 1 i < N - 1 i N - 1 N 1 i++ i++ i {
			int min = Math.min(Math.min(p[i - 1], p[i]), p[i + 1]);
			int max = Math.max(Math.max(p[i - 1], p[i]), p[i + 1]);
			if(min < p[i] && p[i] < max) r++;
		} {
			int min = Math.min(Math.min(p[i - 1], p[i]), p[i + 1]);
			int max = Math.max(Math.max(p[i - 1], p[i]), p[i + 1]);
			if(min < p[i] && p[i] < max) r++;
		} int min = Math.min(Math.min(p[i - 1], p[i]), p[i + 1]); min Math.min(Math.min(p[i - 1], p[i]), p[i + 1]) Math.min Math Math.min(p[i - 1], p[i]) Math.min Math p[i - 1] p i - 1 i 1 p[i] p i p[i + 1] p i + 1 i 1 int max = Math.max(Math.max(p[i - 1], p[i]), p[i + 1]); max Math.max(Math.max(p[i - 1], p[i]), p[i + 1]) Math.max Math Math.max(p[i - 1], p[i]) Math.max Math p[i - 1] p i - 1 i 1 p[i] p i p[i + 1] p i + 1 i 1 if(min < p[i] && p[i] < max) r++; min < p[i] && p[i] < max min < p[i] min p[i] p i p[i] < max p[i] p i max r++ r System.out.println(r) System.out.println System.out System System.out r String[] args args public class Main {
	static int r = 0;
	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();
		}
		sc.close();
		int r = 0;
		for(int i = 1; i < N - 1; i++) {
			int min = Math.min(Math.min(p[i - 1], p[i]), p[i + 1]);
			int max = Math.max(Math.max(p[i - 1], p[i]), p[i + 1]);
			if(min < p[i] && p[i] < max) r++;
		}
		System.out.println(r);
	}
} public class Main {
	static int r = 0;
	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();
		}
		sc.close();
		int r = 0;
		for(int i = 1; i < N - 1; i++) {
			int min = Math.min(Math.min(p[i - 1], p[i]), p[i + 1]);
			int max = Math.max(Math.max(p[i - 1], p[i]), p[i + 1]);
			if(min < p[i] && p[i] < max) r++;
		}
		System.out.println(r);
	}
} Main
import java.util.Scanner;

public class Main {
	static int r = 0;
	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();
		}
		sc.close();
		int r = 0;
		for(int i = 1; i < N - 1; i++) {
			int min = Math.min(Math.min(p[i - 1], p[i]), p[i + 1]);
			int max = Math.max(Math.max(p[i - 1], p[i]), p[i + 1]);
			if(min < p[i] && p[i] < max) r++;
		}
		System.out.println(r);
	}
}	
