import java.util.*;
public class Main {
	
	static int mod = (int)1e9+7;
	
	public static void main(String[] args) {		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt(); //pの個数
		
		int p[] = new int[n];  //{ 0, 0, 0, 0, 0, 0}  n個の配列 
		for(int i=0;i<n;i++) {
			p[i] = sc.nextInt();
		}
		sc.close();
		
		int cnt = 0;
		
		for(int i=0;i<n;i++) {
			if (i+2 >= n) break;
			int x1 = p[i];
			int x2 = p[i+1];
			int x3 = p[i+2];
			
			if( ((x1>=x2)&&(x2>x3)) || (x3>=x2)&&(x2>x1)) cnt++;
			
		}
		
		System.out.println(cnt);
		
	}
	
} import java.util.*; util.* java public class Main {
	
	static int mod = (int)1e9+7;
	
	public static void main(String[] args) {		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt(); //pの個数
		
		int p[] = new int[n];  //{ 0, 0, 0, 0, 0, 0}  n個の配列 
		for(int i=0;i<n;i++) {
			p[i] = sc.nextInt();
		}
		sc.close();
		
		int cnt = 0;
		
		for(int i=0;i<n;i++) {
			if (i+2 >= n) break;
			int x1 = p[i];
			int x2 = p[i+1];
			int x3 = p[i+2];
			
			if( ((x1>=x2)&&(x2>x3)) || (x3>=x2)&&(x2>x1)) cnt++;
			
		}
		
		System.out.println(cnt);
		
	}
	
} Main static int mod = (int)1e9+7; mod (int)1e9+7 (int)1e9 7 public static void main(String[] args) {		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt(); //pの個数
		
		int p[] = new int[n];  //{ 0, 0, 0, 0, 0, 0}  n個の配列 
		for(int i=0;i<n;i++) {
			p[i] = sc.nextInt();
		}
		sc.close();
		
		int cnt = 0;
		
		for(int i=0;i<n;i++) {
			if (i+2 >= n) break;
			int x1 = p[i];
			int x2 = p[i+1];
			int x3 = p[i+2];
			
			if( ((x1>=x2)&&(x2>x3)) || (x3>=x2)&&(x2>x1)) cnt++;
			
		}
		
		System.out.println(cnt);
		
	} main {		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt(); //pの個数
		
		int p[] = new int[n];  //{ 0, 0, 0, 0, 0, 0}  n個の配列 
		for(int i=0;i<n;i++) {
			p[i] = sc.nextInt();
		}
		sc.close();
		
		int cnt = 0;
		
		for(int i=0;i<n;i++) {
			if (i+2 >= n) break;
			int x1 = p[i];
			int x2 = p[i+1];
			int x3 = p[i+2];
			
			if( ((x1>=x2)&&(x2>x3)) || (x3>=x2)&&(x2>x1)) 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] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc sc.close() sc.close sc int cnt = 0; cnt 0 for(int i=0;i<n;i++) {
			if (i+2 >= n) break;
			int x1 = p[i];
			int x2 = p[i+1];
			int x3 = p[i+2];
			
			if( ((x1>=x2)&&(x2>x3)) || (x3>=x2)&&(x2>x1)) cnt++;
			
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			if (i+2 >= n) break;
			int x1 = p[i];
			int x2 = p[i+1];
			int x3 = p[i+2];
			
			if( ((x1>=x2)&&(x2>x3)) || (x3>=x2)&&(x2>x1)) cnt++;
			
		} {
			if (i+2 >= n) break;
			int x1 = p[i];
			int x2 = p[i+1];
			int x3 = p[i+2];
			
			if( ((x1>=x2)&&(x2>x3)) || (x3>=x2)&&(x2>x1)) cnt++;
			
		} if (i+2 >= n) break; i+2 >= n i+2 i 2 n break; int x1 = p[i]; x1 p[i] p i int x2 = p[i+1]; x2 p[i+1] p i+1 i 1 int x3 = p[i+2]; x3 p[i+2] p i+2 i 2 if( ((x1>=x2)&&(x2>x3)) || (x3>=x2)&&(x2>x1)) cnt++; ((x1>=x2)&&(x2>x3)) || (x3>=x2)&&(x2>x1) ((x1>=x2)&&(x2>x3)) (x1>=x2) x1 x2 (x2>x3) x2 x3 (x3>=x2)&&(x2>x1) (x3>=x2) x3 x2 (x2>x1) x2 x1 cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
	
	static int mod = (int)1e9+7;
	
	public static void main(String[] args) {		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt(); //pの個数
		
		int p[] = new int[n];  //{ 0, 0, 0, 0, 0, 0}  n個の配列 
		for(int i=0;i<n;i++) {
			p[i] = sc.nextInt();
		}
		sc.close();
		
		int cnt = 0;
		
		for(int i=0;i<n;i++) {
			if (i+2 >= n) break;
			int x1 = p[i];
			int x2 = p[i+1];
			int x3 = p[i+2];
			
			if( ((x1>=x2)&&(x2>x3)) || (x3>=x2)&&(x2>x1)) cnt++;
			
		}
		
		System.out.println(cnt);
		
	}
	
} public class Main {
	
	static int mod = (int)1e9+7;
	
	public static void main(String[] args) {		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt(); //pの個数
		
		int p[] = new int[n];  //{ 0, 0, 0, 0, 0, 0}  n個の配列 
		for(int i=0;i<n;i++) {
			p[i] = sc.nextInt();
		}
		sc.close();
		
		int cnt = 0;
		
		for(int i=0;i<n;i++) {
			if (i+2 >= n) break;
			int x1 = p[i];
			int x2 = p[i+1];
			int x3 = p[i+2];
			
			if( ((x1>=x2)&&(x2>x3)) || (x3>=x2)&&(x2>x1)) cnt++;
			
		}
		
		System.out.println(cnt);
		
	}
	
} Main
import java.util.*;
public class Main {
	
	static int mod = (int)1e9+7;
	
	public static void main(String[] args) {		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt(); //pの個数
		
		int p[] = new int[n];  //{ 0, 0, 0, 0, 0, 0}  n個の配列 
		for(int i=0;i<n;i++) {
			p[i] = sc.nextInt();
		}
		sc.close();
		
		int cnt = 0;
		
		for(int i=0;i<n;i++) {
			if (i+2 >= n) break;
			int x1 = p[i];
			int x2 = p[i+1];
			int x3 = p[i+2];
			
			if( ((x1>=x2)&&(x2>x3)) || (x3>=x2)&&(x2>x1)) cnt++;
			
		}
		
		System.out.println(cnt);
		
	}
	
}