import java.util.Scanner;

public class Main {

	public static int min2(int a, int b, int c) {
		int min = Math.min(a, b);
		int min2 = Math.min(b, c);
		int min3 = Math.min(a, c);
		if (min == min2)
			return min3;
		else if (min == min3)
			return min2;
		return min;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p[] = new int[n];
		for (int i = 0; i < n; ++i)
			p[i] = sc.nextInt();
		sc.close();
		int cnt = 0;
		for (int i = 1; i < n - 1; ++i) {
			int min2 = min2(p[i - 1], p[i], p[i + 1]);
			if (p[i] == min2)
				++cnt;
		}
		System.out.println(cnt);
	}

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

	public static int min2(int a, int b, int c) {
		int min = Math.min(a, b);
		int min2 = Math.min(b, c);
		int min3 = Math.min(a, c);
		if (min == min2)
			return min3;
		else if (min == min3)
			return min2;
		return min;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p[] = new int[n];
		for (int i = 0; i < n; ++i)
			p[i] = sc.nextInt();
		sc.close();
		int cnt = 0;
		for (int i = 1; i < n - 1; ++i) {
			int min2 = min2(p[i - 1], p[i], p[i + 1]);
			if (p[i] == min2)
				++cnt;
		}
		System.out.println(cnt);
	}

} Main public static int min2(int a, int b, int c) {
		int min = Math.min(a, b);
		int min2 = Math.min(b, c);
		int min3 = Math.min(a, c);
		if (min == min2)
			return min3;
		else if (min == min3)
			return min2;
		return min;
	} min2 {
		int min = Math.min(a, b);
		int min2 = Math.min(b, c);
		int min3 = Math.min(a, c);
		if (min == min2)
			return min3;
		else if (min == min3)
			return min2;
		return min;
	} int min = Math.min(a, b); min Math.min(a, b) Math.min Math a b int min2 = Math.min(b, c); min2 Math.min(b, c) Math.min Math b c int min3 = Math.min(a, c); min3 Math.min(a, c) Math.min Math a c if (min == min2)
			return min3;
		else if (min == min3)
			return min2; min == min2 min min2 return min3; min3 if (min == min3)
			return min2; min == min3 min min3 return min2; min2 return min; min int a a int b b int c c public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p[] = new int[n];
		for (int i = 0; i < n; ++i)
			p[i] = sc.nextInt();
		sc.close();
		int cnt = 0;
		for (int i = 1; i < n - 1; ++i) {
			int min2 = min2(p[i - 1], p[i], p[i + 1]);
			if (p[i] == min2)
				++cnt;
		}
		System.out.println(cnt);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p[] = new int[n];
		for (int i = 0; i < n; ++i)
			p[i] = sc.nextInt();
		sc.close();
		int cnt = 0;
		for (int i = 1; i < n - 1; ++i) {
			int min2 = min2(p[i - 1], p[i], p[i + 1]);
			if (p[i] == min2)
				++cnt;
		}
		System.out.println(cnt);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int p[] = new int[n]; p new int[n] n for (int i = 0; i < n; ++i)
			p[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < n i n ++i ++i i p[i] = sc.nextInt(); p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc sc.close() sc.close sc int cnt = 0; cnt 0 for (int i = 1; i < n - 1; ++i) {
			int min2 = min2(p[i - 1], p[i], p[i + 1]);
			if (p[i] == min2)
				++cnt;
		} int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 ++i ++i i {
			int min2 = min2(p[i - 1], p[i], p[i + 1]);
			if (p[i] == min2)
				++cnt;
		} {
			int min2 = min2(p[i - 1], p[i], p[i + 1]);
			if (p[i] == min2)
				++cnt;
		} int min2 = min2(p[i - 1], p[i], p[i + 1]); min2 min2(p[i - 1], p[i], p[i + 1]) min2 p[i - 1] p i - 1 i 1 p[i] p i p[i + 1] p i + 1 i 1 if (p[i] == min2)
				++cnt; p[i] == min2 p[i] p i min2 ++cnt cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {

	public static int min2(int a, int b, int c) {
		int min = Math.min(a, b);
		int min2 = Math.min(b, c);
		int min3 = Math.min(a, c);
		if (min == min2)
			return min3;
		else if (min == min3)
			return min2;
		return min;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p[] = new int[n];
		for (int i = 0; i < n; ++i)
			p[i] = sc.nextInt();
		sc.close();
		int cnt = 0;
		for (int i = 1; i < n - 1; ++i) {
			int min2 = min2(p[i - 1], p[i], p[i + 1]);
			if (p[i] == min2)
				++cnt;
		}
		System.out.println(cnt);
	}

} public class Main {

	public static int min2(int a, int b, int c) {
		int min = Math.min(a, b);
		int min2 = Math.min(b, c);
		int min3 = Math.min(a, c);
		if (min == min2)
			return min3;
		else if (min == min3)
			return min2;
		return min;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p[] = new int[n];
		for (int i = 0; i < n; ++i)
			p[i] = sc.nextInt();
		sc.close();
		int cnt = 0;
		for (int i = 1; i < n - 1; ++i) {
			int min2 = min2(p[i - 1], p[i], p[i + 1]);
			if (p[i] == min2)
				++cnt;
		}
		System.out.println(cnt);
	}

} Main
import java.util.Scanner;

public class Main {

	public static int min2(int a, int b, int c) {
		int min = Math.min(a, b);
		int min2 = Math.min(b, c);
		int min3 = Math.min(a, c);
		if (min == min2)
			return min3;
		else if (min == min3)
			return min2;
		return min;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p[] = new int[n];
		for (int i = 0; i < n; ++i)
			p[i] = sc.nextInt();
		sc.close();
		int cnt = 0;
		for (int i = 1; i < n - 1; ++i) {
			int min2 = min2(p[i - 1], p[i], p[i + 1]);
			if (p[i] == min2)
				++cnt;
		}
		System.out.println(cnt);
	}

}
