import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		
		int left = in.nextInt();
		int center = in.nextInt();
		int ans = 0;
		for(int i=2; i<n; i++) {
			int right = in.nextInt();
			if(Math.min(left, Math.min(center, right))!=center && Math.max(left,  Math.max(center, right))!=center) {
				ans++;
			}
			left = center;
			center = right;
		}
		System.out.println(ans);
		
		
		in.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		
		int left = in.nextInt();
		int center = in.nextInt();
		int ans = 0;
		for(int i=2; i<n; i++) {
			int right = in.nextInt();
			if(Math.min(left, Math.min(center, right))!=center && Math.max(left,  Math.max(center, right))!=center) {
				ans++;
			}
			left = center;
			center = right;
		}
		System.out.println(ans);
		
		
		in.close();
	}
} Main public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		
		int left = in.nextInt();
		int center = in.nextInt();
		int ans = 0;
		for(int i=2; i<n; i++) {
			int right = in.nextInt();
			if(Math.min(left, Math.min(center, right))!=center && Math.max(left,  Math.max(center, right))!=center) {
				ans++;
			}
			left = center;
			center = right;
		}
		System.out.println(ans);
		
		
		in.close();
	} main {
		Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		
		int left = in.nextInt();
		int center = in.nextInt();
		int ans = 0;
		for(int i=2; i<n; i++) {
			int right = in.nextInt();
			if(Math.min(left, Math.min(center, right))!=center && Math.max(left,  Math.max(center, right))!=center) {
				ans++;
			}
			left = center;
			center = right;
		}
		System.out.println(ans);
		
		
		in.close();
	} Scanner in = new java.util.Scanner(System.in); in new java.util.Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int left = in.nextInt(); left in.nextInt() in.nextInt in int center = in.nextInt(); center in.nextInt() in.nextInt in int ans = 0; ans 0 for(int i=2; i<n; i++) {
			int right = in.nextInt();
			if(Math.min(left, Math.min(center, right))!=center && Math.max(left,  Math.max(center, right))!=center) {
				ans++;
			}
			left = center;
			center = right;
		} int i=2; int i=2; i 2 i<n i n i++ i++ i {
			int right = in.nextInt();
			if(Math.min(left, Math.min(center, right))!=center && Math.max(left,  Math.max(center, right))!=center) {
				ans++;
			}
			left = center;
			center = right;
		} {
			int right = in.nextInt();
			if(Math.min(left, Math.min(center, right))!=center && Math.max(left,  Math.max(center, right))!=center) {
				ans++;
			}
			left = center;
			center = right;
		} int right = in.nextInt(); right in.nextInt() in.nextInt in if(Math.min(left, Math.min(center, right))!=center && Math.max(left,  Math.max(center, right))!=center) {
				ans++;
			} Math.min(left, Math.min(center, right))!=center && Math.max(left,  Math.max(center, right))!=center Math.min(left, Math.min(center, right))!=center Math.min(left, Math.min(center, right)) Math.min Math left Math.min(center, right) Math.min Math center right center Math.max(left,  Math.max(center, right))!=center Math.max(left,  Math.max(center, right)) Math.max Math left Math.max(center, right) Math.max Math center right center {
				ans++;
			} ans++ ans left = center left center center = right center right System.out.println(ans) System.out.println System.out System System.out ans in.close() in.close in String[] args args public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		
		int left = in.nextInt();
		int center = in.nextInt();
		int ans = 0;
		for(int i=2; i<n; i++) {
			int right = in.nextInt();
			if(Math.min(left, Math.min(center, right))!=center && Math.max(left,  Math.max(center, right))!=center) {
				ans++;
			}
			left = center;
			center = right;
		}
		System.out.println(ans);
		
		
		in.close();
	}
} public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		
		int left = in.nextInt();
		int center = in.nextInt();
		int ans = 0;
		for(int i=2; i<n; i++) {
			int right = in.nextInt();
			if(Math.min(left, Math.min(center, right))!=center && Math.max(left,  Math.max(center, right))!=center) {
				ans++;
			}
			left = center;
			center = right;
		}
		System.out.println(ans);
		
		
		in.close();
	}
} Main
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		
		int left = in.nextInt();
		int center = in.nextInt();
		int ans = 0;
		for(int i=2; i<n; i++) {
			int right = in.nextInt();
			if(Math.min(left, Math.min(center, right))!=center && Math.max(left,  Math.max(center, right))!=center) {
				ans++;
			}
			left = center;
			center = right;
		}
		System.out.println(ans);
		
		
		in.close();
	}
}
