import java.util.Scanner;

public class Main {
	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();
		}
		
		int count = 0;
		for(int i=0;i<n-2;i++) {
			if(judge(p,i)) count++;
		}
		System.out.println(count);
		
		sc.close();	
	}
	
	private static boolean judge(int[] p,int first) {
		int i1 = p[first];
		int i2 = p[first + 1];
		int i3 = p[first + 2];
		
		if(i1 < i2 && i2 < i3 || i1 > i2 && i2 > i3) {
			return true;
		}else {
			return false;
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	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();
		}
		
		int count = 0;
		for(int i=0;i<n-2;i++) {
			if(judge(p,i)) count++;
		}
		System.out.println(count);
		
		sc.close();	
	}
	
	private static boolean judge(int[] p,int first) {
		int i1 = p[first];
		int i2 = p[first + 1];
		int i3 = p[first + 2];
		
		if(i1 < i2 && i2 < i3 || i1 > i2 && i2 > i3) {
			return true;
		}else {
			return false;
		}
	}
} Main 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();
		}
		
		int count = 0;
		for(int i=0;i<n-2;i++) {
			if(judge(p,i)) count++;
		}
		System.out.println(count);
		
		sc.close();	
	} 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();
		}
		
		int count = 0;
		for(int i=0;i<n-2;i++) {
			if(judge(p,i)) count++;
		}
		System.out.println(count);
		
		sc.close();	
	} 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] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc int count = 0; count 0 for(int i=0;i<n-2;i++) {
			if(judge(p,i)) count++;
		} int i=0; int i=0; i 0 i<n-2 i n-2 n 2 i++ i++ i {
			if(judge(p,i)) count++;
		} {
			if(judge(p,i)) count++;
		} if(judge(p,i)) count++; judge(p,i) judge p i count++ count System.out.println(count) System.out.println System.out System System.out count sc.close() sc.close sc String[] args args private static boolean judge(int[] p,int first) {
		int i1 = p[first];
		int i2 = p[first + 1];
		int i3 = p[first + 2];
		
		if(i1 < i2 && i2 < i3 || i1 > i2 && i2 > i3) {
			return true;
		}else {
			return false;
		}
	} judge {
		int i1 = p[first];
		int i2 = p[first + 1];
		int i3 = p[first + 2];
		
		if(i1 < i2 && i2 < i3 || i1 > i2 && i2 > i3) {
			return true;
		}else {
			return false;
		}
	} int i1 = p[first]; i1 p[first] p first int i2 = p[first + 1]; i2 p[first + 1] p first + 1 first 1 int i3 = p[first + 2]; i3 p[first + 2] p first + 2 first 2 if(i1 < i2 && i2 < i3 || i1 > i2 && i2 > i3) {
			return true;
		}else {
			return false;
		} i1 < i2 && i2 < i3 || i1 > i2 && i2 > i3 i1 < i2 && i2 < i3 i1 < i2 i1 i2 i2 < i3 i2 i3 i1 > i2 && i2 > i3 i1 > i2 i1 i2 i2 > i3 i2 i3 {
			return true;
		} return true; true {
			return false;
		} return false; false int[] p p int first first public class Main {
	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();
		}
		
		int count = 0;
		for(int i=0;i<n-2;i++) {
			if(judge(p,i)) count++;
		}
		System.out.println(count);
		
		sc.close();	
	}
	
	private static boolean judge(int[] p,int first) {
		int i1 = p[first];
		int i2 = p[first + 1];
		int i3 = p[first + 2];
		
		if(i1 < i2 && i2 < i3 || i1 > i2 && i2 > i3) {
			return true;
		}else {
			return false;
		}
	}
} public class Main {
	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();
		}
		
		int count = 0;
		for(int i=0;i<n-2;i++) {
			if(judge(p,i)) count++;
		}
		System.out.println(count);
		
		sc.close();	
	}
	
	private static boolean judge(int[] p,int first) {
		int i1 = p[first];
		int i2 = p[first + 1];
		int i3 = p[first + 2];
		
		if(i1 < i2 && i2 < i3 || i1 > i2 && i2 > i3) {
			return true;
		}else {
			return false;
		}
	}
} Main
import java.util.Scanner;

public class Main {
	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();
		}
		
		int count = 0;
		for(int i=0;i<n-2;i++) {
			if(judge(p,i)) count++;
		}
		System.out.println(count);
		
		sc.close();	
	}
	
	private static boolean judge(int[] p,int first) {
		int i1 = p[first];
		int i2 = p[first + 1];
		int i3 = p[first + 2];
		
		if(i1 < i2 && i2 < i3 || i1 > i2 && i2 > i3) {
			return true;
		}else {
			return false;
		}
	}
}