import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = sc.nextInt();
		int res = 0;
		for(int i = 1; i < n-1; i++){
			int[] three = new int[3];
			three[0] = arr[i];
			three[1] = arr[i-1];
			three[2] = arr[i+1];
			Arrays.sort(three);
			if(three[1] == arr[i]) res++;
		}
		System.out.println(res);
	}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = sc.nextInt();
		int res = 0;
		for(int i = 1; i < n-1; i++){
			int[] three = new int[3];
			three[0] = arr[i];
			three[1] = arr[i-1];
			three[2] = arr[i+1];
			Arrays.sort(three);
			if(three[1] == arr[i]) res++;
		}
		System.out.println(res);
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = sc.nextInt();
		int res = 0;
		for(int i = 1; i < n-1; i++){
			int[] three = new int[3];
			three[0] = arr[i];
			three[1] = arr[i-1];
			three[2] = arr[i+1];
			Arrays.sort(three);
			if(three[1] == arr[i]) res++;
		}
		System.out.println(res);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = sc.nextInt();
		int res = 0;
		for(int i = 1; i < n-1; i++){
			int[] three = new int[3];
			three[0] = arr[i];
			three[1] = arr[i-1];
			three[2] = arr[i+1];
			Arrays.sort(three);
			if(three[1] == arr[i]) res++;
		}
		System.out.println(res);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] arr = new int[n]; arr new int[n] n for(int i = 0; i < n; i++) arr[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i arr[i] = sc.nextInt(); arr[i] = sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc int res = 0; res 0 for(int i = 1; i < n-1; i++){
			int[] three = new int[3];
			three[0] = arr[i];
			three[1] = arr[i-1];
			three[2] = arr[i+1];
			Arrays.sort(three);
			if(three[1] == arr[i]) res++;
		} int i = 1; int i = 1; i 1 i < n-1 i n-1 n 1 i++ i++ i {
			int[] three = new int[3];
			three[0] = arr[i];
			three[1] = arr[i-1];
			three[2] = arr[i+1];
			Arrays.sort(three);
			if(three[1] == arr[i]) res++;
		} {
			int[] three = new int[3];
			three[0] = arr[i];
			three[1] = arr[i-1];
			three[2] = arr[i+1];
			Arrays.sort(three);
			if(three[1] == arr[i]) res++;
		} int[] three = new int[3]; three new int[3] 3 three[0] = arr[i] three[0] three 0 arr[i] arr i three[1] = arr[i-1] three[1] three 1 arr[i-1] arr i-1 i 1 three[2] = arr[i+1] three[2] three 2 arr[i+1] arr i+1 i 1 Arrays.sort(three) Arrays.sort Arrays three if(three[1] == arr[i]) res++; three[1] == arr[i] three[1] three 1 arr[i] arr i res++ res System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = sc.nextInt();
		int res = 0;
		for(int i = 1; i < n-1; i++){
			int[] three = new int[3];
			three[0] = arr[i];
			three[1] = arr[i-1];
			three[2] = arr[i+1];
			Arrays.sort(three);
			if(three[1] == arr[i]) res++;
		}
		System.out.println(res);
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = sc.nextInt();
		int res = 0;
		for(int i = 1; i < n-1; i++){
			int[] three = new int[3];
			three[0] = arr[i];
			three[1] = arr[i-1];
			three[2] = arr[i+1];
			Arrays.sort(three);
			if(three[1] == arr[i]) res++;
		}
		System.out.println(res);
	}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = sc.nextInt();
		int res = 0;
		for(int i = 1; i < n-1; i++){
			int[] three = new int[3];
			three[0] = arr[i];
			three[1] = arr[i-1];
			three[2] = arr[i+1];
			Arrays.sort(three);
			if(three[1] == arr[i]) res++;
		}
		System.out.println(res);
	}

}
