import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int count = 0;
		int prev = sc.nextInt();
		int curr = sc.nextInt();
		for (int i = 2; i < n; i++) {
			int next = sc.nextInt();
			if(curr < prev && curr > next)count++;
			else if(curr > prev && curr < next)count++;
			prev = curr;
			curr = next;
		}
		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 n = sc.nextInt();
		
		int count = 0;
		int prev = sc.nextInt();
		int curr = sc.nextInt();
		for (int i = 2; i < n; i++) {
			int next = sc.nextInt();
			if(curr < prev && curr > next)count++;
			else if(curr > prev && curr < next)count++;
			prev = curr;
			curr = next;
		}
		System.out.println(count);
		
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int count = 0;
		int prev = sc.nextInt();
		int curr = sc.nextInt();
		for (int i = 2; i < n; i++) {
			int next = sc.nextInt();
			if(curr < prev && curr > next)count++;
			else if(curr > prev && curr < next)count++;
			prev = curr;
			curr = next;
		}
		System.out.println(count);
		
	} main {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int count = 0;
		int prev = sc.nextInt();
		int curr = sc.nextInt();
		for (int i = 2; i < n; i++) {
			int next = sc.nextInt();
			if(curr < prev && curr > next)count++;
			else if(curr > prev && curr < next)count++;
			prev = curr;
			curr = next;
		}
		System.out.println(count);
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int count = 0; count 0 int prev = sc.nextInt(); prev sc.nextInt() sc.nextInt sc int curr = sc.nextInt(); curr sc.nextInt() sc.nextInt sc for (int i = 2; i < n; i++) {
			int next = sc.nextInt();
			if(curr < prev && curr > next)count++;
			else if(curr > prev && curr < next)count++;
			prev = curr;
			curr = next;
		} int i = 2; int i = 2; i 2 i < n i n i++ i++ i {
			int next = sc.nextInt();
			if(curr < prev && curr > next)count++;
			else if(curr > prev && curr < next)count++;
			prev = curr;
			curr = next;
		} {
			int next = sc.nextInt();
			if(curr < prev && curr > next)count++;
			else if(curr > prev && curr < next)count++;
			prev = curr;
			curr = next;
		} int next = sc.nextInt(); next sc.nextInt() sc.nextInt sc if(curr < prev && curr > next)count++;
			else if(curr > prev && curr < next)count++; curr < prev && curr > next curr < prev curr prev curr > next curr next count++ count if(curr > prev && curr < next)count++; curr > prev && curr < next curr > prev curr prev curr < next curr next count++ count prev = curr prev curr curr = next curr next 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 n = sc.nextInt();
		
		int count = 0;
		int prev = sc.nextInt();
		int curr = sc.nextInt();
		for (int i = 2; i < n; i++) {
			int next = sc.nextInt();
			if(curr < prev && curr > next)count++;
			else if(curr > prev && curr < next)count++;
			prev = curr;
			curr = next;
		}
		System.out.println(count);
		
	}

} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int count = 0;
		int prev = sc.nextInt();
		int curr = sc.nextInt();
		for (int i = 2; i < n; i++) {
			int next = sc.nextInt();
			if(curr < prev && curr > next)count++;
			else if(curr > prev && curr < next)count++;
			prev = curr;
			curr = next;
		}
		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 n = sc.nextInt();
		
		int count = 0;
		int prev = sc.nextInt();
		int curr = sc.nextInt();
		for (int i = 2; i < n; i++) {
			int next = sc.nextInt();
			if(curr < prev && curr > next)count++;
			else if(curr > prev && curr < next)count++;
			prev = curr;
			curr = next;
		}
		System.out.println(count);
		
	}

}
