import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] array=new int[n];
		int min=99999,sum=0;

		for(int i=0;i<n;i++) {
			array[i]=sc.nextInt();
		}
		for(int i=1;i<n-1;i++) {
			if(array[i]>array[i-1]&&array[i]<array[i+1])sum++;
			else if(array[i]<array[i-1]&&array[i]>array[i+1])sum++;
		}

		System.out.println(sum);


	}
}
/*
 6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
 */

//Arrays.sort(array, (a, b) -> Integer.compare(a[0], b[0]));

 import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] array=new int[n];
		int min=99999,sum=0;

		for(int i=0;i<n;i++) {
			array[i]=sc.nextInt();
		}
		for(int i=1;i<n-1;i++) {
			if(array[i]>array[i-1]&&array[i]<array[i+1])sum++;
			else if(array[i]<array[i-1]&&array[i]>array[i+1])sum++;
		}

		System.out.println(sum);


	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] array=new int[n];
		int min=99999,sum=0;

		for(int i=0;i<n;i++) {
			array[i]=sc.nextInt();
		}
		for(int i=1;i<n-1;i++) {
			if(array[i]>array[i-1]&&array[i]<array[i+1])sum++;
			else if(array[i]<array[i-1]&&array[i]>array[i+1])sum++;
		}

		System.out.println(sum);


	} main {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] array=new int[n];
		int min=99999,sum=0;

		for(int i=0;i<n;i++) {
			array[i]=sc.nextInt();
		}
		for(int i=1;i<n-1;i++) {
			if(array[i]>array[i-1]&&array[i]<array[i+1])sum++;
			else if(array[i]<array[i-1]&&array[i]>array[i+1])sum++;
		}

		System.out.println(sum);


	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] array=new int[n]; array new int[n] n int min=99999 min 99999 sum=0; sum 0 for(int i=0;i<n;i++) {
			array[i]=sc.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			array[i]=sc.nextInt();
		} {
			array[i]=sc.nextInt();
		} array[i]=sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc for(int i=1;i<n-1;i++) {
			if(array[i]>array[i-1]&&array[i]<array[i+1])sum++;
			else if(array[i]<array[i-1]&&array[i]>array[i+1])sum++;
		} int i=1; int i=1; i 1 i<n-1 i n-1 n 1 i++ i++ i {
			if(array[i]>array[i-1]&&array[i]<array[i+1])sum++;
			else if(array[i]<array[i-1]&&array[i]>array[i+1])sum++;
		} {
			if(array[i]>array[i-1]&&array[i]<array[i+1])sum++;
			else if(array[i]<array[i-1]&&array[i]>array[i+1])sum++;
		} if(array[i]>array[i-1]&&array[i]<array[i+1])sum++;
			else if(array[i]<array[i-1]&&array[i]>array[i+1])sum++; array[i]>array[i-1]&&array[i]<array[i+1] array[i]>array[i-1] array[i] array i array[i-1] array i-1 i 1 array[i]<array[i+1] array[i] array i array[i+1] array i+1 i 1 sum++ sum if(array[i]<array[i-1]&&array[i]>array[i+1])sum++; array[i]<array[i-1]&&array[i]>array[i+1] array[i]<array[i-1] array[i] array i array[i-1] array i-1 i 1 array[i]>array[i+1] array[i] array i array[i+1] array i+1 i 1 sum++ sum System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] array=new int[n];
		int min=99999,sum=0;

		for(int i=0;i<n;i++) {
			array[i]=sc.nextInt();
		}
		for(int i=1;i<n-1;i++) {
			if(array[i]>array[i-1]&&array[i]<array[i+1])sum++;
			else if(array[i]<array[i-1]&&array[i]>array[i+1])sum++;
		}

		System.out.println(sum);


	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] array=new int[n];
		int min=99999,sum=0;

		for(int i=0;i<n;i++) {
			array[i]=sc.nextInt();
		}
		for(int i=1;i<n-1;i++) {
			if(array[i]>array[i-1]&&array[i]<array[i+1])sum++;
			else if(array[i]<array[i-1]&&array[i]>array[i+1])sum++;
		}

		System.out.println(sum);


	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] array=new int[n];
		int min=99999,sum=0;

		for(int i=0;i<n;i++) {
			array[i]=sc.nextInt();
		}
		for(int i=1;i<n-1;i++) {
			if(array[i]>array[i-1]&&array[i]<array[i+1])sum++;
			else if(array[i]<array[i-1]&&array[i]>array[i+1])sum++;
		}

		System.out.println(sum);


	}
}
/*
 6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
 */

//Arrays.sort(array, (a, b) -> Integer.compare(a[0], b[0]));


