import java.util.*;
public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=sc.nextInt();
		int c=0;
		for(int i=0;i<n-2;i++){
			if((arr[i+1]>arr[i]&&arr[i+1]<arr[i+2])||(arr[i+1]<arr[i]&&arr[i+1]>arr[i+2]))
				c++;
		}
		System.out.println(c);
	}
} import java.util.*; util.* java public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=sc.nextInt();
		int c=0;
		for(int i=0;i<n-2;i++){
			if((arr[i+1]>arr[i]&&arr[i+1]<arr[i+2])||(arr[i+1]<arr[i]&&arr[i+1]>arr[i+2]))
				c++;
		}
		System.out.println(c);
	}
} Main public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=sc.nextInt();
		int c=0;
		for(int i=0;i<n-2;i++){
			if((arr[i+1]>arr[i]&&arr[i+1]<arr[i+2])||(arr[i+1]<arr[i]&&arr[i+1]>arr[i+2]))
				c++;
		}
		System.out.println(c);
	} main {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=sc.nextInt();
		int c=0;
		for(int i=0;i<n-2;i++){
			if((arr[i+1]>arr[i]&&arr[i+1]<arr[i+2])||(arr[i+1]<arr[i]&&arr[i+1]>arr[i+2]))
				c++;
		}
		System.out.println(c);
	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int arr[]=new int[n]; arr new int[n] n for(int i=0;i<n;i++)
			arr[i]=sc.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i arr[i]=sc.nextInt(); arr[i]=sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc int c=0; c 0 for(int i=0;i<n-2;i++){
			if((arr[i+1]>arr[i]&&arr[i+1]<arr[i+2])||(arr[i+1]<arr[i]&&arr[i+1]>arr[i+2]))
				c++;
		} int i=0; int i=0; i 0 i<n-2 i n-2 n 2 i++ i++ i {
			if((arr[i+1]>arr[i]&&arr[i+1]<arr[i+2])||(arr[i+1]<arr[i]&&arr[i+1]>arr[i+2]))
				c++;
		} {
			if((arr[i+1]>arr[i]&&arr[i+1]<arr[i+2])||(arr[i+1]<arr[i]&&arr[i+1]>arr[i+2]))
				c++;
		} if((arr[i+1]>arr[i]&&arr[i+1]<arr[i+2])||(arr[i+1]<arr[i]&&arr[i+1]>arr[i+2]))
				c++; (arr[i+1]>arr[i]&&arr[i+1]<arr[i+2])||(arr[i+1]<arr[i]&&arr[i+1]>arr[i+2]) (arr[i+1]>arr[i]&&arr[i+1]<arr[i+2]) arr[i+1]>arr[i] arr[i+1] arr i+1 i 1 arr[i] arr i arr[i+1]<arr[i+2] arr[i+1] arr i+1 i 1 arr[i+2] arr i+2 i 2 (arr[i+1]<arr[i]&&arr[i+1]>arr[i+2]) arr[i+1]<arr[i] arr[i+1] arr i+1 i 1 arr[i] arr i arr[i+1]>arr[i+2] arr[i+1] arr i+1 i 1 arr[i+2] arr i+2 i 2 c++ c System.out.println(c) System.out.println System.out System System.out c String arg[] arg public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=sc.nextInt();
		int c=0;
		for(int i=0;i<n-2;i++){
			if((arr[i+1]>arr[i]&&arr[i+1]<arr[i+2])||(arr[i+1]<arr[i]&&arr[i+1]>arr[i+2]))
				c++;
		}
		System.out.println(c);
	}
} public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=sc.nextInt();
		int c=0;
		for(int i=0;i<n-2;i++){
			if((arr[i+1]>arr[i]&&arr[i+1]<arr[i+2])||(arr[i+1]<arr[i]&&arr[i+1]>arr[i+2]))
				c++;
		}
		System.out.println(c);
	}
} Main
import java.util.*;
public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=sc.nextInt();
		int c=0;
		for(int i=0;i<n-2;i++){
			if((arr[i+1]>arr[i]&&arr[i+1]<arr[i+2])||(arr[i+1]<arr[i]&&arr[i+1]>arr[i+2]))
				c++;
		}
		System.out.println(c);
	}
}