import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int[] b = new int[a];
		int c;
		int d;
		int e;
		int f;
		int count = 0;
		for(int i = 0; a>i; i++) {
			c = sc.nextInt();
			b[i] = c;
		}

		for(int i = 1; a-1 > i ; i++) {
			d = b[i-1];
			e = b[i];
			f = b[i+1];
			if((e > d || e > f) && (e < d || e < f)) {
				count++;
			}
		}
		System.out.println(count);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int[] b = new int[a];
		int c;
		int d;
		int e;
		int f;
		int count = 0;
		for(int i = 0; a>i; i++) {
			c = sc.nextInt();
			b[i] = c;
		}

		for(int i = 1; a-1 > i ; i++) {
			d = b[i-1];
			e = b[i];
			f = b[i+1];
			if((e > d || e > f) && (e < d || e < f)) {
				count++;
			}
		}
		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int[] b = new int[a];
		int c;
		int d;
		int e;
		int f;
		int count = 0;
		for(int i = 0; a>i; i++) {
			c = sc.nextInt();
			b[i] = c;
		}

		for(int i = 1; a-1 > i ; i++) {
			d = b[i-1];
			e = b[i];
			f = b[i+1];
			if((e > d || e > f) && (e < d || e < f)) {
				count++;
			}
		}
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int[] b = new int[a];
		int c;
		int d;
		int e;
		int f;
		int count = 0;
		for(int i = 0; a>i; i++) {
			c = sc.nextInt();
			b[i] = c;
		}

		for(int i = 1; a-1 > i ; i++) {
			d = b[i-1];
			e = b[i];
			f = b[i+1];
			if((e > d || e > f) && (e < d || e < f)) {
				count++;
			}
		}
		System.out.println(count);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int[] b = new int[a]; b new int[a] a int c; c int d; d int e; e int f; f int count = 0; count 0 for(int i = 0; a>i; i++) {
			c = sc.nextInt();
			b[i] = c;
		} int i = 0; int i = 0; i 0 a>i a i i++ i++ i {
			c = sc.nextInt();
			b[i] = c;
		} {
			c = sc.nextInt();
			b[i] = c;
		} c = sc.nextInt() c sc.nextInt() sc.nextInt sc b[i] = c b[i] b i c for(int i = 1; a-1 > i ; i++) {
			d = b[i-1];
			e = b[i];
			f = b[i+1];
			if((e > d || e > f) && (e < d || e < f)) {
				count++;
			}
		} int i = 1; int i = 1; i 1 a-1 > i a-1 a 1 i i++ i++ i {
			d = b[i-1];
			e = b[i];
			f = b[i+1];
			if((e > d || e > f) && (e < d || e < f)) {
				count++;
			}
		} {
			d = b[i-1];
			e = b[i];
			f = b[i+1];
			if((e > d || e > f) && (e < d || e < f)) {
				count++;
			}
		} d = b[i-1] d b[i-1] b i-1 i 1 e = b[i] e b[i] b i f = b[i+1] f b[i+1] b i+1 i 1 if((e > d || e > f) && (e < d || e < f)) {
				count++;
			} (e > d || e > f) && (e < d || e < f) (e > d || e > f) e > d e d e > f e f (e < d || e < f) e < d e d e < f e f {
				count++;
			} count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int[] b = new int[a];
		int c;
		int d;
		int e;
		int f;
		int count = 0;
		for(int i = 0; a>i; i++) {
			c = sc.nextInt();
			b[i] = c;
		}

		for(int i = 1; a-1 > i ; i++) {
			d = b[i-1];
			e = b[i];
			f = b[i+1];
			if((e > d || e > f) && (e < d || e < f)) {
				count++;
			}
		}
		System.out.println(count);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int[] b = new int[a];
		int c;
		int d;
		int e;
		int f;
		int count = 0;
		for(int i = 0; a>i; i++) {
			c = sc.nextInt();
			b[i] = c;
		}

		for(int i = 1; a-1 > i ; i++) {
			d = b[i-1];
			e = b[i];
			f = b[i+1];
			if((e > d || e > f) && (e < d || e < f)) {
				count++;
			}
		}
		System.out.println(count);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int[] b = new int[a];
		int c;
		int d;
		int e;
		int f;
		int count = 0;
		for(int i = 0; a>i; i++) {
			c = sc.nextInt();
			b[i] = c;
		}

		for(int i = 1; a-1 > i ; i++) {
			d = b[i-1];
			e = b[i];
			f = b[i+1];
			if((e > d || e > f) && (e < d || e < f)) {
				count++;
			}
		}
		System.out.println(count);
	}
}