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

public class Main {
	public static void main(String[] args){

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();

		int[] p=new int[N];

		for(int i=0;i<N;i++) p[i]=sc.nextInt();

		sc.close();

		int cnt=0;

		for(int i=0;i<N-2;i++){

			int second=min_2(p[i],p[i+1],p[i+2]);

			if(p[i+1]==second) cnt++;
		}

		System.out.println(cnt);

	}

	public static int min_2(int a,int b,int c){

		int[] box=new int[3];

		box[0]=a;
		box[1]=b;
		box[2]=c;

		Arrays.sort(box);

		return box[1];
	}
} import java.util.Arrays; Arrays java.util 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[] p=new int[N];

		for(int i=0;i<N;i++) p[i]=sc.nextInt();

		sc.close();

		int cnt=0;

		for(int i=0;i<N-2;i++){

			int second=min_2(p[i],p[i+1],p[i+2]);

			if(p[i+1]==second) cnt++;
		}

		System.out.println(cnt);

	}

	public static int min_2(int a,int b,int c){

		int[] box=new int[3];

		box[0]=a;
		box[1]=b;
		box[2]=c;

		Arrays.sort(box);

		return box[1];
	}
} Main public static void main(String[] args){

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();

		int[] p=new int[N];

		for(int i=0;i<N;i++) p[i]=sc.nextInt();

		sc.close();

		int cnt=0;

		for(int i=0;i<N-2;i++){

			int second=min_2(p[i],p[i+1],p[i+2]);

			if(p[i+1]==second) cnt++;
		}

		System.out.println(cnt);

	} main {

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();

		int[] p=new int[N];

		for(int i=0;i<N;i++) p[i]=sc.nextInt();

		sc.close();

		int cnt=0;

		for(int i=0;i<N-2;i++){

			int second=min_2(p[i],p[i+1],p[i+2]);

			if(p[i+1]==second) cnt++;
		}

		System.out.println(cnt);

	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int N=sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] p=new int[N]; p new int[N] N for(int i=0;i<N;i++) p[i]=sc.nextInt(); int i=0; int i=0; i 0 i<N i N i++ i++ i p[i]=sc.nextInt(); p[i]=sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc sc.close() sc.close sc int cnt=0; cnt 0 for(int i=0;i<N-2;i++){

			int second=min_2(p[i],p[i+1],p[i+2]);

			if(p[i+1]==second) cnt++;
		} int i=0; int i=0; i 0 i<N-2 i N-2 N 2 i++ i++ i {

			int second=min_2(p[i],p[i+1],p[i+2]);

			if(p[i+1]==second) cnt++;
		} {

			int second=min_2(p[i],p[i+1],p[i+2]);

			if(p[i+1]==second) cnt++;
		} int second=min_2(p[i],p[i+1],p[i+2]); second min_2(p[i],p[i+1],p[i+2]) min_2 p[i] p i p[i+1] p i+1 i 1 p[i+2] p i+2 i 2 if(p[i+1]==second) cnt++; p[i+1]==second p[i+1] p i+1 i 1 second cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public static int min_2(int a,int b,int c){

		int[] box=new int[3];

		box[0]=a;
		box[1]=b;
		box[2]=c;

		Arrays.sort(box);

		return box[1];
	} min_2 {

		int[] box=new int[3];

		box[0]=a;
		box[1]=b;
		box[2]=c;

		Arrays.sort(box);

		return box[1];
	} int[] box=new int[3]; box new int[3] 3 box[0]=a box[0] box 0 a box[1]=b box[1] box 1 b box[2]=c box[2] box 2 c Arrays.sort(box) Arrays.sort Arrays box return box[1]; box[1] box 1 int a a int b b int c c public class Main {
	public static void main(String[] args){

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();

		int[] p=new int[N];

		for(int i=0;i<N;i++) p[i]=sc.nextInt();

		sc.close();

		int cnt=0;

		for(int i=0;i<N-2;i++){

			int second=min_2(p[i],p[i+1],p[i+2]);

			if(p[i+1]==second) cnt++;
		}

		System.out.println(cnt);

	}

	public static int min_2(int a,int b,int c){

		int[] box=new int[3];

		box[0]=a;
		box[1]=b;
		box[2]=c;

		Arrays.sort(box);

		return box[1];
	}
} public class Main {
	public static void main(String[] args){

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();

		int[] p=new int[N];

		for(int i=0;i<N;i++) p[i]=sc.nextInt();

		sc.close();

		int cnt=0;

		for(int i=0;i<N-2;i++){

			int second=min_2(p[i],p[i+1],p[i+2]);

			if(p[i+1]==second) cnt++;
		}

		System.out.println(cnt);

	}

	public static int min_2(int a,int b,int c){

		int[] box=new int[3];

		box[0]=a;
		box[1]=b;
		box[2]=c;

		Arrays.sort(box);

		return box[1];
	}
} Main

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

public class Main {
	public static void main(String[] args){

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();

		int[] p=new int[N];

		for(int i=0;i<N;i++) p[i]=sc.nextInt();

		sc.close();

		int cnt=0;

		for(int i=0;i<N-2;i++){

			int second=min_2(p[i],p[i+1],p[i+2]);

			if(p[i+1]==second) cnt++;
		}

		System.out.println(cnt);

	}

	public static int min_2(int a,int b,int c){

		int[] box=new int[3];

		box[0]=a;
		box[1]=b;
		box[2]=c;

		Arrays.sort(box);

		return box[1];
	}
}
