import java.util.*;

public class Main {
	public static void main(String [] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), p [] = new int [n], k = 0;
		for (int i = 0; i < n; p[i] = sc.nextInt(), i++);
		for (int i = n - 2; i > 0; k += (((p[i - 1] < p[i]) && (p[i] < p[i + 1])) || ((p[i - 1] > p[i]) && (p[i] > p[i + 1]))) ? 1 : 0, i--);
		System.out.println(k);
  	}
} import java.util.*; util.* java public class Main {
	public static void main(String [] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), p [] = new int [n], k = 0;
		for (int i = 0; i < n; p[i] = sc.nextInt(), i++);
		for (int i = n - 2; i > 0; k += (((p[i - 1] < p[i]) && (p[i] < p[i + 1])) || ((p[i - 1] > p[i]) && (p[i] > p[i + 1]))) ? 1 : 0, i--);
		System.out.println(k);
  	}
} Main public static void main(String [] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), p [] = new int [n], k = 0;
		for (int i = 0; i < n; p[i] = sc.nextInt(), i++);
		for (int i = n - 2; i > 0; k += (((p[i - 1] < p[i]) && (p[i] < p[i + 1])) || ((p[i - 1] > p[i]) && (p[i] > p[i + 1]))) ? 1 : 0, i--);
		System.out.println(k);
  	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), p [] = new int [n], k = 0;
		for (int i = 0; i < n; p[i] = sc.nextInt(), i++);
		for (int i = n - 2; i > 0; k += (((p[i - 1] < p[i]) && (p[i] < p[i + 1])) || ((p[i - 1] > p[i]) && (p[i] > p[i + 1]))) ? 1 : 0, i--);
		System.out.println(k);
  	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt() n sc.nextInt() sc.nextInt sc p [] = new int [n] p new int [n] n k = 0; k 0 for (int i = 0; i < n; p[i] = sc.nextInt(), i++); int i = 0; int i = 0; i 0 i < n i n p[i] = sc.nextInt(), i++ p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc i++ i ; for (int i = n - 2; i > 0; k += (((p[i - 1] < p[i]) && (p[i] < p[i + 1])) || ((p[i - 1] > p[i]) && (p[i] > p[i + 1]))) ? 1 : 0, i--); int i = n - 2; int i = n - 2; i n - 2 n 2 i > 0 i 0 k += (((p[i - 1] < p[i]) && (p[i] < p[i + 1])) || ((p[i - 1] > p[i]) && (p[i] > p[i + 1]))) ? 1 : 0, i-- k += (((p[i - 1] < p[i]) && (p[i] < p[i + 1])) || ((p[i - 1] > p[i]) && (p[i] > p[i + 1]))) ? 1 : 0 k (((p[i - 1] < p[i]) && (p[i] < p[i + 1])) || ((p[i - 1] > p[i]) && (p[i] > p[i + 1]))) ? 1 : 0 (((p[i - 1] < p[i]) && (p[i] < p[i + 1])) || ((p[i - 1] > p[i]) && (p[i] > p[i + 1]))) ((p[i - 1] < p[i]) && (p[i] < p[i + 1])) (p[i - 1] < p[i]) p[i - 1] p i - 1 i 1 p[i] p i (p[i] < p[i + 1]) p[i] p i p[i + 1] p i + 1 i 1 ((p[i - 1] > p[i]) && (p[i] > p[i + 1])) (p[i - 1] > p[i]) p[i - 1] p i - 1 i 1 p[i] p i (p[i] > p[i + 1]) p[i] p i p[i + 1] p i + 1 i 1 1 0 i-- i ; System.out.println(k) System.out.println System.out System System.out k String [] args args public class Main {
	public static void main(String [] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), p [] = new int [n], k = 0;
		for (int i = 0; i < n; p[i] = sc.nextInt(), i++);
		for (int i = n - 2; i > 0; k += (((p[i - 1] < p[i]) && (p[i] < p[i + 1])) || ((p[i - 1] > p[i]) && (p[i] > p[i + 1]))) ? 1 : 0, i--);
		System.out.println(k);
  	}
} public class Main {
	public static void main(String [] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), p [] = new int [n], k = 0;
		for (int i = 0; i < n; p[i] = sc.nextInt(), i++);
		for (int i = n - 2; i > 0; k += (((p[i - 1] < p[i]) && (p[i] < p[i + 1])) || ((p[i - 1] > p[i]) && (p[i] > p[i + 1]))) ? 1 : 0, i--);
		System.out.println(k);
  	}
} Main
import java.util.*;

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