import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		int result=0;

		for (int i = 0; i < n; i++) {
			int p= sc.nextInt();
			list.add(p);
		}

		for (int i = 1; i < n-1; i++) {
			int pi =list.get(i);
			int pIminus =list.get(i-1);
			int pIplus =list.get(i+1);
			// System.out.println("i " + i);
			// System.out.println("pi " + pi);
			if((pIminus<pi && pi<pIplus)|| (pIplus<pi&& pi<pIminus)){
				result++;
			}
		}

			System.out.println(result);

	}

} import java.util.*; util.* java import java.math.*; math.* java import java.lang.*; lang.* java public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		int result=0;

		for (int i = 0; i < n; i++) {
			int p= sc.nextInt();
			list.add(p);
		}

		for (int i = 1; i < n-1; i++) {
			int pi =list.get(i);
			int pIminus =list.get(i-1);
			int pIplus =list.get(i+1);
			// System.out.println("i " + i);
			// System.out.println("pi " + pi);
			if((pIminus<pi && pi<pIplus)|| (pIplus<pi&& pi<pIminus)){
				result++;
			}
		}

			System.out.println(result);

	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		int result=0;

		for (int i = 0; i < n; i++) {
			int p= sc.nextInt();
			list.add(p);
		}

		for (int i = 1; i < n-1; i++) {
			int pi =list.get(i);
			int pIminus =list.get(i-1);
			int pIplus =list.get(i+1);
			// System.out.println("i " + i);
			// System.out.println("pi " + pi);
			if((pIminus<pi && pi<pIplus)|| (pIplus<pi&& pi<pIminus)){
				result++;
			}
		}

			System.out.println(result);

	} main {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		int result=0;

		for (int i = 0; i < n; i++) {
			int p= sc.nextInt();
			list.add(p);
		}

		for (int i = 1; i < n-1; i++) {
			int pi =list.get(i);
			int pIminus =list.get(i-1);
			int pIplus =list.get(i+1);
			// System.out.println("i " + i);
			// System.out.println("pi " + pi);
			if((pIminus<pi && pi<pIplus)|| (pIplus<pi&& pi<pIminus)){
				result++;
			}
		}

			System.out.println(result);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc List<Integer> list = new ArrayList<>(); list new ArrayList<>() int result=0; result 0 for (int i = 0; i < n; i++) {
			int p= sc.nextInt();
			list.add(p);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int p= sc.nextInt();
			list.add(p);
		} {
			int p= sc.nextInt();
			list.add(p);
		} int p= sc.nextInt(); p sc.nextInt() sc.nextInt sc list.add(p) list.add list p for (int i = 1; i < n-1; i++) {
			int pi =list.get(i);
			int pIminus =list.get(i-1);
			int pIplus =list.get(i+1);
			// System.out.println("i " + i);
			// System.out.println("pi " + pi);
			if((pIminus<pi && pi<pIplus)|| (pIplus<pi&& pi<pIminus)){
				result++;
			}
		} int i = 1; int i = 1; i 1 i < n-1 i n-1 n 1 i++ i++ i {
			int pi =list.get(i);
			int pIminus =list.get(i-1);
			int pIplus =list.get(i+1);
			// System.out.println("i " + i);
			// System.out.println("pi " + pi);
			if((pIminus<pi && pi<pIplus)|| (pIplus<pi&& pi<pIminus)){
				result++;
			}
		} {
			int pi =list.get(i);
			int pIminus =list.get(i-1);
			int pIplus =list.get(i+1);
			// System.out.println("i " + i);
			// System.out.println("pi " + pi);
			if((pIminus<pi && pi<pIplus)|| (pIplus<pi&& pi<pIminus)){
				result++;
			}
		} int pi =list.get(i); pi list.get(i) list.get list i int pIminus =list.get(i-1); pIminus list.get(i-1) list.get list i-1 i 1 int pIplus =list.get(i+1); pIplus list.get(i+1) list.get list i+1 i 1 if((pIminus<pi && pi<pIplus)|| (pIplus<pi&& pi<pIminus)){
				result++;
			} (pIminus<pi && pi<pIplus)|| (pIplus<pi&& pi<pIminus) (pIminus<pi && pi<pIplus) pIminus<pi pIminus pi pi<pIplus pi pIplus (pIplus<pi&& pi<pIminus) pIplus<pi pIplus pi pi<pIminus pi pIminus {
				result++;
			} result++ result System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		int result=0;

		for (int i = 0; i < n; i++) {
			int p= sc.nextInt();
			list.add(p);
		}

		for (int i = 1; i < n-1; i++) {
			int pi =list.get(i);
			int pIminus =list.get(i-1);
			int pIplus =list.get(i+1);
			// System.out.println("i " + i);
			// System.out.println("pi " + pi);
			if((pIminus<pi && pi<pIplus)|| (pIplus<pi&& pi<pIminus)){
				result++;
			}
		}

			System.out.println(result);

	}

} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		int result=0;

		for (int i = 0; i < n; i++) {
			int p= sc.nextInt();
			list.add(p);
		}

		for (int i = 1; i < n-1; i++) {
			int pi =list.get(i);
			int pIminus =list.get(i-1);
			int pIplus =list.get(i+1);
			// System.out.println("i " + i);
			// System.out.println("pi " + pi);
			if((pIminus<pi && pi<pIplus)|| (pIplus<pi&& pi<pIminus)){
				result++;
			}
		}

			System.out.println(result);

	}

} Main
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		int result=0;

		for (int i = 0; i < n; i++) {
			int p= sc.nextInt();
			list.add(p);
		}

		for (int i = 1; i < n-1; i++) {
			int pi =list.get(i);
			int pIminus =list.get(i-1);
			int pIplus =list.get(i+1);
			// System.out.println("i " + i);
			// System.out.println("pi " + pi);
			if((pIminus<pi && pi<pIplus)|| (pIplus<pi&& pi<pIminus)){
				result++;
			}
		}

			System.out.println(result);

	}

}
