import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = Integer.parseInt(scanner.nextLine());
		String[] temp = scanner.nextLine().split(" ");
		int[] list = new int[n];
		int ans   = 0;



		for(int i = 0; i < n; i++) {


			list[i] = Integer.parseInt(temp[i]);

			if(i > 1) {

				if((list[i - 2] > list[i - 1] && list[i] < list[i - 1]) ||(list[i - 2] < list[i - 1] && list[i] > list[i - 1])) {
				ans++;
				}
			}
		}


		System.out.println(ans);

	}

} import java.util.Scanner; Scanner java.util public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = Integer.parseInt(scanner.nextLine());
		String[] temp = scanner.nextLine().split(" ");
		int[] list = new int[n];
		int ans   = 0;



		for(int i = 0; i < n; i++) {


			list[i] = Integer.parseInt(temp[i]);

			if(i > 1) {

				if((list[i - 2] > list[i - 1] && list[i] < list[i - 1]) ||(list[i - 2] < list[i - 1] && list[i] > list[i - 1])) {
				ans++;
				}
			}
		}


		System.out.println(ans);

	}

} Main public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = Integer.parseInt(scanner.nextLine());
		String[] temp = scanner.nextLine().split(" ");
		int[] list = new int[n];
		int ans   = 0;



		for(int i = 0; i < n; i++) {


			list[i] = Integer.parseInt(temp[i]);

			if(i > 1) {

				if((list[i - 2] > list[i - 1] && list[i] < list[i - 1]) ||(list[i - 2] < list[i - 1] && list[i] > list[i - 1])) {
				ans++;
				}
			}
		}


		System.out.println(ans);

	} main {

		Scanner scanner = new Scanner(System.in);

		int n = Integer.parseInt(scanner.nextLine());
		String[] temp = scanner.nextLine().split(" ");
		int[] list = new int[n];
		int ans   = 0;



		for(int i = 0; i < n; i++) {


			list[i] = Integer.parseInt(temp[i]);

			if(i > 1) {

				if((list[i - 2] > list[i - 1] && list[i] < list[i - 1]) ||(list[i - 2] < list[i - 1] && list[i] > list[i - 1])) {
				ans++;
				}
			}
		}


		System.out.println(ans);

	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = Integer.parseInt(scanner.nextLine()); n Integer.parseInt(scanner.nextLine()) Integer.parseInt Integer scanner.nextLine() scanner.nextLine scanner String[] temp = scanner.nextLine().split(" "); temp scanner.nextLine().split(" ") scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " int[] list = new int[n]; list new int[n] n int ans   = 0; ans 0 for(int i = 0; i < n; i++) {


			list[i] = Integer.parseInt(temp[i]);

			if(i > 1) {

				if((list[i - 2] > list[i - 1] && list[i] < list[i - 1]) ||(list[i - 2] < list[i - 1] && list[i] > list[i - 1])) {
				ans++;
				}
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {


			list[i] = Integer.parseInt(temp[i]);

			if(i > 1) {

				if((list[i - 2] > list[i - 1] && list[i] < list[i - 1]) ||(list[i - 2] < list[i - 1] && list[i] > list[i - 1])) {
				ans++;
				}
			}
		} {


			list[i] = Integer.parseInt(temp[i]);

			if(i > 1) {

				if((list[i - 2] > list[i - 1] && list[i] < list[i - 1]) ||(list[i - 2] < list[i - 1] && list[i] > list[i - 1])) {
				ans++;
				}
			}
		} list[i] = Integer.parseInt(temp[i]) list[i] list i Integer.parseInt(temp[i]) Integer.parseInt Integer temp[i] temp i if(i > 1) {

				if((list[i - 2] > list[i - 1] && list[i] < list[i - 1]) ||(list[i - 2] < list[i - 1] && list[i] > list[i - 1])) {
				ans++;
				}
			} i > 1 i 1 {

				if((list[i - 2] > list[i - 1] && list[i] < list[i - 1]) ||(list[i - 2] < list[i - 1] && list[i] > list[i - 1])) {
				ans++;
				}
			} if((list[i - 2] > list[i - 1] && list[i] < list[i - 1]) ||(list[i - 2] < list[i - 1] && list[i] > list[i - 1])) {
				ans++;
				} (list[i - 2] > list[i - 1] && list[i] < list[i - 1]) ||(list[i - 2] < list[i - 1] && list[i] > list[i - 1]) (list[i - 2] > list[i - 1] && list[i] < list[i - 1]) list[i - 2] > list[i - 1] list[i - 2] list i - 2 i 2 list[i - 1] list i - 1 i 1 list[i] < list[i - 1] list[i] list i list[i - 1] list i - 1 i 1 (list[i - 2] < list[i - 1] && list[i] > list[i - 1]) list[i - 2] < list[i - 1] list[i - 2] list i - 2 i 2 list[i - 1] list i - 1 i 1 list[i] > list[i - 1] list[i] list i list[i - 1] list i - 1 i 1 {
				ans++;
				} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = Integer.parseInt(scanner.nextLine());
		String[] temp = scanner.nextLine().split(" ");
		int[] list = new int[n];
		int ans   = 0;



		for(int i = 0; i < n; i++) {


			list[i] = Integer.parseInt(temp[i]);

			if(i > 1) {

				if((list[i - 2] > list[i - 1] && list[i] < list[i - 1]) ||(list[i - 2] < list[i - 1] && list[i] > list[i - 1])) {
				ans++;
				}
			}
		}


		System.out.println(ans);

	}

} public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = Integer.parseInt(scanner.nextLine());
		String[] temp = scanner.nextLine().split(" ");
		int[] list = new int[n];
		int ans   = 0;



		for(int i = 0; i < n; i++) {


			list[i] = Integer.parseInt(temp[i]);

			if(i > 1) {

				if((list[i - 2] > list[i - 1] && list[i] < list[i - 1]) ||(list[i - 2] < list[i - 1] && list[i] > list[i - 1])) {
				ans++;
				}
			}
		}


		System.out.println(ans);

	}

} Main
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = Integer.parseInt(scanner.nextLine());
		String[] temp = scanner.nextLine().split(" ");
		int[] list = new int[n];
		int ans   = 0;



		for(int i = 0; i < n; i++) {


			list[i] = Integer.parseInt(temp[i]);

			if(i > 1) {

				if((list[i - 2] > list[i - 1] && list[i] < list[i - 1]) ||(list[i - 2] < list[i - 1] && list[i] > list[i - 1])) {
				ans++;
				}
			}
		}


		System.out.println(ans);

	}

}
