import java.io.PrintWriter;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

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

		int ans = 0;
		for(int i=0; i<N-2; i++){
			if(p[i]<p[i+1] && p[i+1]<p[i+2] || p[i+2]<p[i+1]&&p[i+1]<p[i])ans++;
		}
		out.println(ans);

		out.flush();
	}
}
 import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

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

		int ans = 0;
		for(int i=0; i<N-2; i++){
			if(p[i]<p[i+1] && p[i+1]<p[i+2] || p[i+2]<p[i+1]&&p[i+1]<p[i])ans++;
		}
		out.println(ans);

		out.flush();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

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

		int ans = 0;
		for(int i=0; i<N-2; i++){
			if(p[i]<p[i+1] && p[i+1]<p[i+2] || p[i+2]<p[i+1]&&p[i+1]<p[i])ans++;
		}
		out.println(ans);

		out.flush();
	} main {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

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

		int ans = 0;
		for(int i=0; i<N-2; i++){
			if(p[i]<p[i+1] && p[i+1]<p[i+2] || p[i+2]<p[i+1]&&p[i+1]<p[i])ans++;
		}
		out.println(ans);

		out.flush();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) 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 int ans = 0; ans 0 for(int i=0; i<N-2; i++){
			if(p[i]<p[i+1] && p[i+1]<p[i+2] || p[i+2]<p[i+1]&&p[i+1]<p[i])ans++;
		} int i=0; int i=0; i 0 i<N-2 i N-2 N 2 i++ i++ i {
			if(p[i]<p[i+1] && p[i+1]<p[i+2] || p[i+2]<p[i+1]&&p[i+1]<p[i])ans++;
		} {
			if(p[i]<p[i+1] && p[i+1]<p[i+2] || p[i+2]<p[i+1]&&p[i+1]<p[i])ans++;
		} if(p[i]<p[i+1] && p[i+1]<p[i+2] || p[i+2]<p[i+1]&&p[i+1]<p[i])ans++; p[i]<p[i+1] && p[i+1]<p[i+2] || p[i+2]<p[i+1]&&p[i+1]<p[i] p[i]<p[i+1] && p[i+1]<p[i+2] p[i]<p[i+1] p[i] p i p[i+1] p i+1 i 1 p[i+1]<p[i+2] p[i+1] p i+1 i 1 p[i+2] p i+2 i 2 p[i+2]<p[i+1]&&p[i+1]<p[i] p[i+2]<p[i+1] p[i+2] p i+2 i 2 p[i+1] p i+1 i 1 p[i+1]<p[i] p[i+1] p i+1 i 1 p[i] p i ans++ ans out.println(ans) out.println out ans out.flush() out.flush out String[] args args
import java.io.PrintWriter;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

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

		int ans = 0;
		for(int i=0; i<N-2; i++){
			if(p[i]<p[i+1] && p[i+1]<p[i+2] || p[i+2]<p[i+1]&&p[i+1]<p[i])ans++;
		}
		out.println(ans);

		out.flush();
	}
}

