import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; i++)
			p[i] = in.nextInt();
		System.out.println(solve(p));
		in.close();
	}

	private static int solve(int[] p) {
		int r = 0;
		for (int i = 1; i < p.length - 1; i++)
			if (p[i - 1] < p[i] && p[i] <= p[i + 1])
				r++;
			else if (p[i] > p[i + 1] && p[i] <= p[i - 1])
				r++;
		return r;
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Arrays; Arrays java.util import java.util.Comparator; Comparator java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; i++)
			p[i] = in.nextInt();
		System.out.println(solve(p));
		in.close();
	}

	private static int solve(int[] p) {
		int r = 0;
		for (int i = 1; i < p.length - 1; i++)
			if (p[i - 1] < p[i] && p[i] <= p[i + 1])
				r++;
			else if (p[i] > p[i + 1] && p[i] <= p[i - 1])
				r++;
		return r;
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; i++)
			p[i] = in.nextInt();
		System.out.println(solve(p));
		in.close();
	} main {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; i++)
			p[i] = in.nextInt();
		System.out.println(solve(p));
		in.close();
	} Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); in new Scanner(new BufferedReader(new InputStreamReader(System.in))) int n = in.nextInt(); n in.nextInt() in.nextInt in int[] p = new int[n]; p new int[n] n for (int i = 0; i < n; i++)
			p[i] = in.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i p[i] = in.nextInt(); p[i] = in.nextInt() p[i] p i in.nextInt() in.nextInt in System.out.println(solve(p)) System.out.println System.out System System.out solve(p) solve p in.close() in.close in String[] args args private static int solve(int[] p) {
		int r = 0;
		for (int i = 1; i < p.length - 1; i++)
			if (p[i - 1] < p[i] && p[i] <= p[i + 1])
				r++;
			else if (p[i] > p[i + 1] && p[i] <= p[i - 1])
				r++;
		return r;
	} solve {
		int r = 0;
		for (int i = 1; i < p.length - 1; i++)
			if (p[i - 1] < p[i] && p[i] <= p[i + 1])
				r++;
			else if (p[i] > p[i + 1] && p[i] <= p[i - 1])
				r++;
		return r;
	} int r = 0; r 0 for (int i = 1; i < p.length - 1; i++)
			if (p[i - 1] < p[i] && p[i] <= p[i + 1])
				r++;
			else if (p[i] > p[i + 1] && p[i] <= p[i - 1])
				r++; int i = 1; int i = 1; i 1 i < p.length - 1 i p.length - 1 p.length p p.length 1 i++ i++ i if (p[i - 1] < p[i] && p[i] <= p[i + 1])
				r++;
			else if (p[i] > p[i + 1] && p[i] <= p[i - 1])
				r++; if (p[i - 1] < p[i] && p[i] <= p[i + 1])
				r++;
			else if (p[i] > p[i + 1] && p[i] <= p[i - 1])
				r++; 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 r++ r if (p[i] > p[i + 1] && p[i] <= p[i - 1])
				r++; p[i] > p[i + 1] && p[i] <= p[i - 1] p[i] > p[i + 1] p[i] p i p[i + 1] p i + 1 i 1 p[i] <= p[i - 1] p[i] p i p[i - 1] p i - 1 i 1 r++ r return r; r int[] p p public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; i++)
			p[i] = in.nextInt();
		System.out.println(solve(p));
		in.close();
	}

	private static int solve(int[] p) {
		int r = 0;
		for (int i = 1; i < p.length - 1; i++)
			if (p[i - 1] < p[i] && p[i] <= p[i + 1])
				r++;
			else if (p[i] > p[i + 1] && p[i] <= p[i - 1])
				r++;
		return r;
	}
} public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; i++)
			p[i] = in.nextInt();
		System.out.println(solve(p));
		in.close();
	}

	private static int solve(int[] p) {
		int r = 0;
		for (int i = 1; i < p.length - 1; i++)
			if (p[i - 1] < p[i] && p[i] <= p[i + 1])
				r++;
			else if (p[i] > p[i + 1] && p[i] <= p[i - 1])
				r++;
		return r;
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; i++)
			p[i] = in.nextInt();
		System.out.println(solve(p));
		in.close();
	}

	private static int solve(int[] p) {
		int r = 0;
		for (int i = 1; i < p.length - 1; i++)
			if (p[i - 1] < p[i] && p[i] <= p[i + 1])
				r++;
			else if (p[i] > p[i + 1] && p[i] <= p[i - 1])
				r++;
		return r;
	}
}
