import java.util.ArrayList;
import java.util.Scanner;
 class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int count = 0 ;
		int arr[] = new int[n]; 
		for(int i = 0 ; i< n ;i++) {
			arr[i] = scan.nextInt();
		}
		
		//ArrayList<Integer> a = new ArrayList<>();
		for(int i = 1 ; i <n-1 ; i++) {
			if(Second(arr[i-1],arr[i],arr[i+1]) == arr[i]){
				count++;
				
			}
		}
		System.out.print(count);

		
	}

	static int Second(int a , int b , int x) {
		int first = a  , second = b ;

			if(second < first ) {
				first = b ; 
				second = a ;
			}
			if(x < second ) {
				second = x  ;
			}
			if(second < first ) {
				int temp = first ;
				first = second ;
				second = temp ;
			}
		return second ;
		
	}
} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int count = 0 ;
		int arr[] = new int[n]; 
		for(int i = 0 ; i< n ;i++) {
			arr[i] = scan.nextInt();
		}
		
		//ArrayList<Integer> a = new ArrayList<>();
		for(int i = 1 ; i <n-1 ; i++) {
			if(Second(arr[i-1],arr[i],arr[i+1]) == arr[i]){
				count++;
				
			}
		}
		System.out.print(count);

		
	}

	static int Second(int a , int b , int x) {
		int first = a  , second = b ;

			if(second < first ) {
				first = b ; 
				second = a ;
			}
			if(x < second ) {
				second = x  ;
			}
			if(second < first ) {
				int temp = first ;
				first = second ;
				second = temp ;
			}
		return second ;
		
	}
} Main public static void main(String[]args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int count = 0 ;
		int arr[] = new int[n]; 
		for(int i = 0 ; i< n ;i++) {
			arr[i] = scan.nextInt();
		}
		
		//ArrayList<Integer> a = new ArrayList<>();
		for(int i = 1 ; i <n-1 ; i++) {
			if(Second(arr[i-1],arr[i],arr[i+1]) == arr[i]){
				count++;
				
			}
		}
		System.out.print(count);

		
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int count = 0 ;
		int arr[] = new int[n]; 
		for(int i = 0 ; i< n ;i++) {
			arr[i] = scan.nextInt();
		}
		
		//ArrayList<Integer> a = new ArrayList<>();
		for(int i = 1 ; i <n-1 ; i++) {
			if(Second(arr[i-1],arr[i],arr[i+1]) == arr[i]){
				count++;
				
			}
		}
		System.out.print(count);

		
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int count = 0 ; count 0 int arr[] = new int[n]; arr new int[n] n for(int i = 0 ; i< n ;i++) {
			arr[i] = scan.nextInt();
		} int i = 0 ; int i = 0 ; i 0 i< n i n i++ i++ i {
			arr[i] = scan.nextInt();
		} {
			arr[i] = scan.nextInt();
		} arr[i] = scan.nextInt() arr[i] arr i scan.nextInt() scan.nextInt scan for(int i = 1 ; i <n-1 ; i++) {
			if(Second(arr[i-1],arr[i],arr[i+1]) == arr[i]){
				count++;
				
			}
		} int i = 1 ; int i = 1 ; i 1 i <n-1 i n-1 n 1 i++ i++ i {
			if(Second(arr[i-1],arr[i],arr[i+1]) == arr[i]){
				count++;
				
			}
		} {
			if(Second(arr[i-1],arr[i],arr[i+1]) == arr[i]){
				count++;
				
			}
		} if(Second(arr[i-1],arr[i],arr[i+1]) == arr[i]){
				count++;
				
			} Second(arr[i-1],arr[i],arr[i+1]) == arr[i] Second(arr[i-1],arr[i],arr[i+1]) Second arr[i-1] arr i-1 i 1 arr[i] arr i arr[i+1] arr i+1 i 1 arr[i] arr i {
				count++;
				
			} count++ count System.out.print(count) System.out.print System.out System System.out count String[]args args static int Second(int a , int b , int x) {
		int first = a  , second = b ;

			if(second < first ) {
				first = b ; 
				second = a ;
			}
			if(x < second ) {
				second = x  ;
			}
			if(second < first ) {
				int temp = first ;
				first = second ;
				second = temp ;
			}
		return second ;
		
	} Second {
		int first = a  , second = b ;

			if(second < first ) {
				first = b ; 
				second = a ;
			}
			if(x < second ) {
				second = x  ;
			}
			if(second < first ) {
				int temp = first ;
				first = second ;
				second = temp ;
			}
		return second ;
		
	} int first = a first a second = b ; second b if(second < first ) {
				first = b ; 
				second = a ;
			} second < first second first {
				first = b ; 
				second = a ;
			} first = b first b second = a second a if(x < second ) {
				second = x  ;
			} x < second x second {
				second = x  ;
			} second = x second x if(second < first ) {
				int temp = first ;
				first = second ;
				second = temp ;
			} second < first second first {
				int temp = first ;
				first = second ;
				second = temp ;
			} int temp = first ; temp first first = second first second second = temp second temp return second ; second int a a int b b int x x
import java.util.ArrayList;
import java.util.Scanner;
 class Main {
	public static void main(String[]args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int count = 0 ;
		int arr[] = new int[n]; 
		for(int i = 0 ; i< n ;i++) {
			arr[i] = scan.nextInt();
		}
		
		//ArrayList<Integer> a = new ArrayList<>();
		for(int i = 1 ; i <n-1 ; i++) {
			if(Second(arr[i-1],arr[i],arr[i+1]) == arr[i]){
				count++;
				
			}
		}
		System.out.print(count);

		
	}

	static int Second(int a , int b , int x) {
		int first = a  , second = b ;

			if(second < first ) {
				first = b ; 
				second = a ;
			}
			if(x < second ) {
				second = x  ;
			}
			if(second < first ) {
				int temp = first ;
				first = second ;
				second = temp ;
			}
		return second ;
		
	}
}