import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		
		int[]P = new int[N];
		
		for(int i = 0; i < N; i++) {
				P[i] = keyboard.nextInt();	
		}
		
		int a = 0;
		int b = 0;
		int count = 0;
		
		for(int i = 1; i < N-1; i++) {
			if(P[i-1] > P[i+1]){
				a = P[i-1];
				b = P[i+1];
			}else {
				a = P[i+1];
				b = P[i-1];
			}
			if(a > P[i] && P[i] > b) {
				count++;
			}
		}
		System.out.println(count);
		keyboard.close();	
	}
} import java.util.Arrays; Arrays java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		
		int[]P = new int[N];
		
		for(int i = 0; i < N; i++) {
				P[i] = keyboard.nextInt();	
		}
		
		int a = 0;
		int b = 0;
		int count = 0;
		
		for(int i = 1; i < N-1; i++) {
			if(P[i-1] > P[i+1]){
				a = P[i-1];
				b = P[i+1];
			}else {
				a = P[i+1];
				b = P[i-1];
			}
			if(a > P[i] && P[i] > b) {
				count++;
			}
		}
		System.out.println(count);
		keyboard.close();	
	}
} Main public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		
		int[]P = new int[N];
		
		for(int i = 0; i < N; i++) {
				P[i] = keyboard.nextInt();	
		}
		
		int a = 0;
		int b = 0;
		int count = 0;
		
		for(int i = 1; i < N-1; i++) {
			if(P[i-1] > P[i+1]){
				a = P[i-1];
				b = P[i+1];
			}else {
				a = P[i+1];
				b = P[i-1];
			}
			if(a > P[i] && P[i] > b) {
				count++;
			}
		}
		System.out.println(count);
		keyboard.close();	
	} main {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		
		int[]P = new int[N];
		
		for(int i = 0; i < N; i++) {
				P[i] = keyboard.nextInt();	
		}
		
		int a = 0;
		int b = 0;
		int count = 0;
		
		for(int i = 1; i < N-1; i++) {
			if(P[i-1] > P[i+1]){
				a = P[i-1];
				b = P[i+1];
			}else {
				a = P[i+1];
				b = P[i-1];
			}
			if(a > P[i] && P[i] > b) {
				count++;
			}
		}
		System.out.println(count);
		keyboard.close();	
	} Scanner keyboard = new Scanner(System.in); keyboard new Scanner(System.in) int N  = keyboard.nextInt(); N keyboard.nextInt() keyboard.nextInt keyboard int[]P = new int[N]; P new int[N] N for(int i = 0; i < N; i++) {
				P[i] = keyboard.nextInt();	
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
				P[i] = keyboard.nextInt();	
		} {
				P[i] = keyboard.nextInt();	
		} P[i] = keyboard.nextInt() P[i] P i keyboard.nextInt() keyboard.nextInt keyboard int a = 0; a 0 int b = 0; b 0 int count = 0; count 0 for(int i = 1; i < N-1; i++) {
			if(P[i-1] > P[i+1]){
				a = P[i-1];
				b = P[i+1];
			}else {
				a = P[i+1];
				b = P[i-1];
			}
			if(a > P[i] && P[i] > b) {
				count++;
			}
		} int i = 1; int i = 1; i 1 i < N-1 i N-1 N 1 i++ i++ i {
			if(P[i-1] > P[i+1]){
				a = P[i-1];
				b = P[i+1];
			}else {
				a = P[i+1];
				b = P[i-1];
			}
			if(a > P[i] && P[i] > b) {
				count++;
			}
		} {
			if(P[i-1] > P[i+1]){
				a = P[i-1];
				b = P[i+1];
			}else {
				a = P[i+1];
				b = P[i-1];
			}
			if(a > P[i] && P[i] > b) {
				count++;
			}
		} if(P[i-1] > P[i+1]){
				a = P[i-1];
				b = P[i+1];
			}else {
				a = P[i+1];
				b = P[i-1];
			} P[i-1] > P[i+1] P[i-1] P i-1 i 1 P[i+1] P i+1 i 1 {
				a = P[i-1];
				b = P[i+1];
			} a = P[i-1] a P[i-1] P i-1 i 1 b = P[i+1] b P[i+1] P i+1 i 1 {
				a = P[i+1];
				b = P[i-1];
			} a = P[i+1] a P[i+1] P i+1 i 1 b = P[i-1] b P[i-1] P i-1 i 1 if(a > P[i] && P[i] > b) {
				count++;
			} a > P[i] && P[i] > b a > P[i] a P[i] P i P[i] > b P[i] P i b {
				count++;
			} count++ count System.out.println(count) System.out.println System.out System System.out count keyboard.close() keyboard.close keyboard String[] args args public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		
		int[]P = new int[N];
		
		for(int i = 0; i < N; i++) {
				P[i] = keyboard.nextInt();	
		}
		
		int a = 0;
		int b = 0;
		int count = 0;
		
		for(int i = 1; i < N-1; i++) {
			if(P[i-1] > P[i+1]){
				a = P[i-1];
				b = P[i+1];
			}else {
				a = P[i+1];
				b = P[i-1];
			}
			if(a > P[i] && P[i] > b) {
				count++;
			}
		}
		System.out.println(count);
		keyboard.close();	
	}
} public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		
		int[]P = new int[N];
		
		for(int i = 0; i < N; i++) {
				P[i] = keyboard.nextInt();	
		}
		
		int a = 0;
		int b = 0;
		int count = 0;
		
		for(int i = 1; i < N-1; i++) {
			if(P[i-1] > P[i+1]){
				a = P[i-1];
				b = P[i+1];
			}else {
				a = P[i+1];
				b = P[i-1];
			}
			if(a > P[i] && P[i] > b) {
				count++;
			}
		}
		System.out.println(count);
		keyboard.close();	
	}
} Main
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		
		int[]P = new int[N];
		
		for(int i = 0; i < N; i++) {
				P[i] = keyboard.nextInt();	
		}
		
		int a = 0;
		int b = 0;
		int count = 0;
		
		for(int i = 1; i < N-1; i++) {
			if(P[i-1] > P[i+1]){
				a = P[i-1];
				b = P[i+1];
			}else {
				a = P[i+1];
				b = P[i-1];
			}
			if(a > P[i] && P[i] > b) {
				count++;
			}
		}
		System.out.println(count);
		keyboard.close();	
	}
}