import java.util.Scanner;
import java.util.InputMismatchException;

public class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		String inputN = scanner.nextLine();
		
		String inputP = scanner.nextLine();
		String[] pStr = inputP.split(" ", 0);
		
		int n = Integer.parseInt(inputN);
		int pInt[] = new int[n];
		for(int i=0;i<n;i++){
			pInt[i] = Integer.parseInt(pStr[i]);
		}
		
		int iCount = 0;
		
		for(int i=0;i+2<n;i++){
			if(pInt[i] > pInt[i+1] && pInt[i+1] > pInt[i+2]){
				iCount++;
			} else if(pInt[i] < pInt[i+1] && pInt[i+1] < pInt[i+2]){
				iCount++;
			}
		}
		
		System.out.println(iCount);
	}
} import java.util.Scanner; Scanner java.util import java.util.InputMismatchException; InputMismatchException java.util public class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		String inputN = scanner.nextLine();
		
		String inputP = scanner.nextLine();
		String[] pStr = inputP.split(" ", 0);
		
		int n = Integer.parseInt(inputN);
		int pInt[] = new int[n];
		for(int i=0;i<n;i++){
			pInt[i] = Integer.parseInt(pStr[i]);
		}
		
		int iCount = 0;
		
		for(int i=0;i+2<n;i++){
			if(pInt[i] > pInt[i+1] && pInt[i+1] > pInt[i+2]){
				iCount++;
			} else if(pInt[i] < pInt[i+1] && pInt[i+1] < pInt[i+2]){
				iCount++;
			}
		}
		
		System.out.println(iCount);
	}
} Main public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		String inputN = scanner.nextLine();
		
		String inputP = scanner.nextLine();
		String[] pStr = inputP.split(" ", 0);
		
		int n = Integer.parseInt(inputN);
		int pInt[] = new int[n];
		for(int i=0;i<n;i++){
			pInt[i] = Integer.parseInt(pStr[i]);
		}
		
		int iCount = 0;
		
		for(int i=0;i+2<n;i++){
			if(pInt[i] > pInt[i+1] && pInt[i+1] > pInt[i+2]){
				iCount++;
			} else if(pInt[i] < pInt[i+1] && pInt[i+1] < pInt[i+2]){
				iCount++;
			}
		}
		
		System.out.println(iCount);
	} main {
		Scanner scanner = new Scanner(System.in);
		String inputN = scanner.nextLine();
		
		String inputP = scanner.nextLine();
		String[] pStr = inputP.split(" ", 0);
		
		int n = Integer.parseInt(inputN);
		int pInt[] = new int[n];
		for(int i=0;i<n;i++){
			pInt[i] = Integer.parseInt(pStr[i]);
		}
		
		int iCount = 0;
		
		for(int i=0;i+2<n;i++){
			if(pInt[i] > pInt[i+1] && pInt[i+1] > pInt[i+2]){
				iCount++;
			} else if(pInt[i] < pInt[i+1] && pInt[i+1] < pInt[i+2]){
				iCount++;
			}
		}
		
		System.out.println(iCount);
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String inputN = scanner.nextLine(); inputN scanner.nextLine() scanner.nextLine scanner String inputP = scanner.nextLine(); inputP scanner.nextLine() scanner.nextLine scanner String[] pStr = inputP.split(" ", 0); pStr inputP.split(" ", 0) inputP.split inputP " " 0 int n = Integer.parseInt(inputN); n Integer.parseInt(inputN) Integer.parseInt Integer inputN int pInt[] = new int[n]; pInt new int[n] n for(int i=0;i<n;i++){
			pInt[i] = Integer.parseInt(pStr[i]);
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			pInt[i] = Integer.parseInt(pStr[i]);
		} {
			pInt[i] = Integer.parseInt(pStr[i]);
		} pInt[i] = Integer.parseInt(pStr[i]) pInt[i] pInt i Integer.parseInt(pStr[i]) Integer.parseInt Integer pStr[i] pStr i int iCount = 0; iCount 0 for(int i=0;i+2<n;i++){
			if(pInt[i] > pInt[i+1] && pInt[i+1] > pInt[i+2]){
				iCount++;
			} else if(pInt[i] < pInt[i+1] && pInt[i+1] < pInt[i+2]){
				iCount++;
			}
		} int i=0; int i=0; i 0 i+2<n i+2 i 2 n i++ i++ i {
			if(pInt[i] > pInt[i+1] && pInt[i+1] > pInt[i+2]){
				iCount++;
			} else if(pInt[i] < pInt[i+1] && pInt[i+1] < pInt[i+2]){
				iCount++;
			}
		} {
			if(pInt[i] > pInt[i+1] && pInt[i+1] > pInt[i+2]){
				iCount++;
			} else if(pInt[i] < pInt[i+1] && pInt[i+1] < pInt[i+2]){
				iCount++;
			}
		} if(pInt[i] > pInt[i+1] && pInt[i+1] > pInt[i+2]){
				iCount++;
			} else if(pInt[i] < pInt[i+1] && pInt[i+1] < pInt[i+2]){
				iCount++;
			} pInt[i] > pInt[i+1] && pInt[i+1] > pInt[i+2] pInt[i] > pInt[i+1] pInt[i] pInt i pInt[i+1] pInt i+1 i 1 pInt[i+1] > pInt[i+2] pInt[i+1] pInt i+1 i 1 pInt[i+2] pInt i+2 i 2 {
				iCount++;
			} iCount++ iCount if(pInt[i] < pInt[i+1] && pInt[i+1] < pInt[i+2]){
				iCount++;
			} pInt[i] < pInt[i+1] && pInt[i+1] < pInt[i+2] pInt[i] < pInt[i+1] pInt[i] pInt i pInt[i+1] pInt i+1 i 1 pInt[i+1] < pInt[i+2] pInt[i+1] pInt i+1 i 1 pInt[i+2] pInt i+2 i 2 {
				iCount++;
			} iCount++ iCount System.out.println(iCount) System.out.println System.out System System.out iCount String[] args args public class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		String inputN = scanner.nextLine();
		
		String inputP = scanner.nextLine();
		String[] pStr = inputP.split(" ", 0);
		
		int n = Integer.parseInt(inputN);
		int pInt[] = new int[n];
		for(int i=0;i<n;i++){
			pInt[i] = Integer.parseInt(pStr[i]);
		}
		
		int iCount = 0;
		
		for(int i=0;i+2<n;i++){
			if(pInt[i] > pInt[i+1] && pInt[i+1] > pInt[i+2]){
				iCount++;
			} else if(pInt[i] < pInt[i+1] && pInt[i+1] < pInt[i+2]){
				iCount++;
			}
		}
		
		System.out.println(iCount);
	}
} public class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		String inputN = scanner.nextLine();
		
		String inputP = scanner.nextLine();
		String[] pStr = inputP.split(" ", 0);
		
		int n = Integer.parseInt(inputN);
		int pInt[] = new int[n];
		for(int i=0;i<n;i++){
			pInt[i] = Integer.parseInt(pStr[i]);
		}
		
		int iCount = 0;
		
		for(int i=0;i+2<n;i++){
			if(pInt[i] > pInt[i+1] && pInt[i+1] > pInt[i+2]){
				iCount++;
			} else if(pInt[i] < pInt[i+1] && pInt[i+1] < pInt[i+2]){
				iCount++;
			}
		}
		
		System.out.println(iCount);
	}
} Main
import java.util.Scanner;
import java.util.InputMismatchException;

public class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		String inputN = scanner.nextLine();
		
		String inputP = scanner.nextLine();
		String[] pStr = inputP.split(" ", 0);
		
		int n = Integer.parseInt(inputN);
		int pInt[] = new int[n];
		for(int i=0;i<n;i++){
			pInt[i] = Integer.parseInt(pStr[i]);
		}
		
		int iCount = 0;
		
		for(int i=0;i+2<n;i++){
			if(pInt[i] > pInt[i+1] && pInt[i+1] > pInt[i+2]){
				iCount++;
			} else if(pInt[i] < pInt[i+1] && pInt[i+1] < pInt[i+2]){
				iCount++;
			}
		}
		
		System.out.println(iCount);
	}
}