import java.util.*;
import java.io.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		int a = sc.nextInt();
		//list.addAll(Arrays.asList(sc.nextLine()));
		for(int k = 1;k <= a; k++) {
			int j = sc.nextInt();
			list.add(j);
		}
		int count = 0;
		for (int i = 1; i < list.size()-1;i++) {
				if (list.get(i-1) < list.get(i) && list.get(i) < list.get(i+1) || list.get(i-1) > list.get(i) && list.get(i) > list.get(i+1)) {
					count++;
				}
		}
		System.out.println(count);
	}
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		int a = sc.nextInt();
		//list.addAll(Arrays.asList(sc.nextLine()));
		for(int k = 1;k <= a; k++) {
			int j = sc.nextInt();
			list.add(j);
		}
		int count = 0;
		for (int i = 1; i < list.size()-1;i++) {
				if (list.get(i-1) < list.get(i) && list.get(i) < list.get(i+1) || list.get(i-1) > list.get(i) && list.get(i) > list.get(i+1)) {
					count++;
				}
		}
		System.out.println(count);
	}
} Main public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		int a = sc.nextInt();
		//list.addAll(Arrays.asList(sc.nextLine()));
		for(int k = 1;k <= a; k++) {
			int j = sc.nextInt();
			list.add(j);
		}
		int count = 0;
		for (int i = 1; i < list.size()-1;i++) {
				if (list.get(i-1) < list.get(i) && list.get(i) < list.get(i+1) || list.get(i-1) > list.get(i) && list.get(i) > list.get(i+1)) {
					count++;
				}
		}
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		int a = sc.nextInt();
		//list.addAll(Arrays.asList(sc.nextLine()));
		for(int k = 1;k <= a; k++) {
			int j = sc.nextInt();
			list.add(j);
		}
		int count = 0;
		for (int i = 1; i < list.size()-1;i++) {
				if (list.get(i-1) < list.get(i) && list.get(i) < list.get(i+1) || list.get(i-1) > list.get(i) && list.get(i) > list.get(i+1)) {
					count++;
				}
		}
		System.out.println(count);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) ArrayList<Integer> list = new ArrayList<Integer>(); list new ArrayList<Integer>() int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc for(int k = 1;k <= a; k++) {
			int j = sc.nextInt();
			list.add(j);
		} int k = 1; int k = 1; k 1 k <= a k a k++ k++ k {
			int j = sc.nextInt();
			list.add(j);
		} {
			int j = sc.nextInt();
			list.add(j);
		} int j = sc.nextInt(); j sc.nextInt() sc.nextInt sc list.add(j) list.add list j int count = 0; count 0 for (int i = 1; i < list.size()-1;i++) {
				if (list.get(i-1) < list.get(i) && list.get(i) < list.get(i+1) || list.get(i-1) > list.get(i) && list.get(i) > list.get(i+1)) {
					count++;
				}
		} int i = 1; int i = 1; i 1 i < list.size()-1 i list.size()-1 list.size() list.size list 1 i++ i++ i {
				if (list.get(i-1) < list.get(i) && list.get(i) < list.get(i+1) || list.get(i-1) > list.get(i) && list.get(i) > list.get(i+1)) {
					count++;
				}
		} {
				if (list.get(i-1) < list.get(i) && list.get(i) < list.get(i+1) || list.get(i-1) > list.get(i) && list.get(i) > list.get(i+1)) {
					count++;
				}
		} if (list.get(i-1) < list.get(i) && list.get(i) < list.get(i+1) || list.get(i-1) > list.get(i) && list.get(i) > list.get(i+1)) {
					count++;
				} list.get(i-1) < list.get(i) && list.get(i) < list.get(i+1) || list.get(i-1) > list.get(i) && list.get(i) > list.get(i+1) list.get(i-1) < list.get(i) && list.get(i) < list.get(i+1) list.get(i-1) < list.get(i) list.get(i-1) list.get list i-1 i 1 list.get(i) list.get list i list.get(i) < list.get(i+1) list.get(i) list.get list i list.get(i+1) list.get list i+1 i 1 list.get(i-1) > list.get(i) && list.get(i) > list.get(i+1) list.get(i-1) > list.get(i) list.get(i-1) list.get list i-1 i 1 list.get(i) list.get list i list.get(i) > list.get(i+1) list.get(i) list.get list i list.get(i+1) list.get list i+1 i 1 {
					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);
		ArrayList<Integer> list = new ArrayList<Integer>();
		int a = sc.nextInt();
		//list.addAll(Arrays.asList(sc.nextLine()));
		for(int k = 1;k <= a; k++) {
			int j = sc.nextInt();
			list.add(j);
		}
		int count = 0;
		for (int i = 1; i < list.size()-1;i++) {
				if (list.get(i-1) < list.get(i) && list.get(i) < list.get(i+1) || list.get(i-1) > list.get(i) && list.get(i) > list.get(i+1)) {
					count++;
				}
		}
		System.out.println(count);
	}
} public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		int a = sc.nextInt();
		//list.addAll(Arrays.asList(sc.nextLine()));
		for(int k = 1;k <= a; k++) {
			int j = sc.nextInt();
			list.add(j);
		}
		int count = 0;
		for (int i = 1; i < list.size()-1;i++) {
				if (list.get(i-1) < list.get(i) && list.get(i) < list.get(i+1) || list.get(i-1) > list.get(i) && list.get(i) > list.get(i+1)) {
					count++;
				}
		}
		System.out.println(count);
	}
} Main
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		int a = sc.nextInt();
		//list.addAll(Arrays.asList(sc.nextLine()));
		for(int k = 1;k <= a; k++) {
			int j = sc.nextInt();
			list.add(j);
		}
		int count = 0;
		for (int i = 1; i < list.size()-1;i++) {
				if (list.get(i-1) < list.get(i) && list.get(i) < list.get(i+1) || list.get(i-1) > list.get(i) && list.get(i) > list.get(i+1)) {
					count++;
				}
		}
		System.out.println(count);
	}
}