import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int[] p = nextIntArray(sc, n);

		sc.close();

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

		out.println(ans);
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
} import java.io.InputStream; InputStream java.io import java.io.PrintStream; PrintStream java.io import java.util.Scanner; Scanner java.util public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int[] p = nextIntArray(sc, n);

		sc.close();

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

		out.println(ans);
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
} Main InputStream in = System.in; in System.in System System.in PrintStream out = System.out; out System.out System System.out public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int[] p = nextIntArray(sc, n);

		sc.close();

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

		out.println(ans);
	} _main {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int[] p = nextIntArray(sc, n);

		sc.close();

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

		out.println(ans);
	} Scanner sc = new Scanner(in); sc new Scanner(in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] p = nextIntArray(sc, n); p nextIntArray(sc, n) nextIntArray sc n sc.close() sc.close sc int ans = 0; ans 0 for (int i = 1; i < n - 1; i++) {
			if (p[i - 1] < p[i] && p[i] < p[i + 1] ||
				p[i - 1] > p[i] && p[i] > p[i + 1]) {
				ans++;
			}
		} int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i {
			if (p[i - 1] < p[i] && p[i] < p[i + 1] ||
				p[i - 1] > p[i] && p[i] > p[i + 1]) {
				ans++;
			}
		} {
			if (p[i - 1] < p[i] && p[i] < p[i + 1] ||
				p[i - 1] > p[i] && p[i] > p[i + 1]) {
				ans++;
			}
		} if (p[i - 1] < p[i] && p[i] < p[i + 1] ||
				p[i - 1] > p[i] && p[i] > p[i + 1]) {
				ans++;
			} p[i - 1] < p[i] && p[i] < p[i + 1] ||
				p[i - 1] > p[i] && p[i] > p[i + 1] 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 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 {
				ans++;
			} ans++ ans out.println(ans) out.println out ans String[] args args public static void main(String[] args) {
		new Main()._main(args);
	} main {
		new Main()._main(args);
	} new Main()._main(args) new Main()._main new Main() args String[] args args @SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	} nextIntArray {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	} int[] result = new int[n]; result new int[n] n for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			result[i] = sc.nextInt();
		} {
			result[i] = sc.nextInt();
		} result[i] = sc.nextInt() result[i] result i sc.nextInt() sc.nextInt sc return result; result Scanner sc sc int n n public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int[] p = nextIntArray(sc, n);

		sc.close();

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

		out.println(ans);
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
} public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int[] p = nextIntArray(sc, n);

		sc.close();

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

		out.println(ans);
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
} Main
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int[] p = nextIntArray(sc, n);

		sc.close();

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

		out.println(ans);
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}
