import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
 
 
public class Main {

	static long MOD = 1_000_000_007;
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		int INF = Integer.MAX_VALUE;
		Scanner sc = new Scanner(System.in);
		//char[] c = sc.next().toCharArray();
		//int N = A.length;
		int N = Integer.parseInt(sc.next());
		int[] P = new int[N];
		for(int i=0; i<N; i++){
			P[i] = Integer.parseInt(sc.next());
		}
		
		int ans = 0;
		
		for(int i=1;i<N-1;i++){
			if((P[i-1]>P[i] && P[i]>P[i+1])||(P[i-1]<P[i] && P[i]<P[i+1]))ans++;
		}
		
		System.out.println(ans);
		
	}
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (c/b);
	}
}
 import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.HashMap; HashMap java.util import java.util.HashSet; HashSet java.util import java.util.List; List java.util import java.util.Map; Map java.util import java.util.Map.Entry; Entry java.util.Map import java.util.Scanner; Scanner java.util import java.util.Set; Set java.util public class Main {

	static long MOD = 1_000_000_007;
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		int INF = Integer.MAX_VALUE;
		Scanner sc = new Scanner(System.in);
		//char[] c = sc.next().toCharArray();
		//int N = A.length;
		int N = Integer.parseInt(sc.next());
		int[] P = new int[N];
		for(int i=0; i<N; i++){
			P[i] = Integer.parseInt(sc.next());
		}
		
		int ans = 0;
		
		for(int i=1;i<N-1;i++){
			if((P[i-1]>P[i] && P[i]>P[i+1])||(P[i-1]<P[i] && P[i]<P[i+1]))ans++;
		}
		
		System.out.println(ans);
		
	}
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (c/b);
	}
} Main static long MOD = 1_000_000_007; MOD 1_000_000_007 public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		int INF = Integer.MAX_VALUE;
		Scanner sc = new Scanner(System.in);
		//char[] c = sc.next().toCharArray();
		//int N = A.length;
		int N = Integer.parseInt(sc.next());
		int[] P = new int[N];
		for(int i=0; i<N; i++){
			P[i] = Integer.parseInt(sc.next());
		}
		
		int ans = 0;
		
		for(int i=1;i<N-1;i++){
			if((P[i-1]>P[i] && P[i]>P[i+1])||(P[i-1]<P[i] && P[i]<P[i+1]))ans++;
		}
		
		System.out.println(ans);
		
	} main {
		// TODO Auto-generated method stub
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		int INF = Integer.MAX_VALUE;
		Scanner sc = new Scanner(System.in);
		//char[] c = sc.next().toCharArray();
		//int N = A.length;
		int N = Integer.parseInt(sc.next());
		int[] P = new int[N];
		for(int i=0; i<N; i++){
			P[i] = Integer.parseInt(sc.next());
		}
		
		int ans = 0;
		
		for(int i=1;i<N-1;i++){
			if((P[i-1]>P[i] && P[i]>P[i+1])||(P[i-1]<P[i] && P[i]<P[i+1]))ans++;
		}
		
		System.out.println(ans);
		
	} int INF = Integer.MAX_VALUE; INF Integer.MAX_VALUE Integer Integer.MAX_VALUE Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] P = new int[N]; P new int[N] N for(int i=0; i<N; i++){
			P[i] = Integer.parseInt(sc.next());
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			P[i] = Integer.parseInt(sc.next());
		} {
			P[i] = Integer.parseInt(sc.next());
		} P[i] = Integer.parseInt(sc.next()) P[i] P i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int ans = 0; ans 0 for(int i=1;i<N-1;i++){
			if((P[i-1]>P[i] && P[i]>P[i+1])||(P[i-1]<P[i] && P[i]<P[i+1]))ans++;
		} int i=1; int i=1; i 1 i<N-1 i N-1 N 1 i++ i++ i {
			if((P[i-1]>P[i] && P[i]>P[i+1])||(P[i-1]<P[i] && P[i]<P[i+1]))ans++;
		} {
			if((P[i-1]>P[i] && P[i]>P[i+1])||(P[i-1]<P[i] && P[i]<P[i+1]))ans++;
		} if((P[i-1]>P[i] && P[i]>P[i+1])||(P[i-1]<P[i] && P[i]<P[i+1]))ans++; (P[i-1]>P[i] && P[i]>P[i+1])||(P[i-1]<P[i] && P[i]<P[i+1]) (P[i-1]>P[i] && P[i]>P[i+1]) P[i-1]>P[i] P[i-1] P i-1 i 1 P[i] P i P[i]>P[i+1] P[i] P i P[i+1] P i+1 i 1 (P[i-1]<P[i] && P[i]<P[i+1]) P[i-1]<P[i] P[i-1] P i-1 i 1 P[i] P i P[i]<P[i+1] P[i] P i P[i+1] P i+1 i 1 ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (c/b);
	} lcm {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (c/b);
	} long temp; temp long c = a; c a c *= b c b while((temp = a%b)!=0) {
			a = b;
			b = temp;
		} (temp = a%b)!=0 (temp = a%b) temp a%b a b 0 {
			a = b;
			b = temp;
		} a = b a b b = temp b temp return (c/b); (c/b) c b long a a long b b public class Main {

	static long MOD = 1_000_000_007;
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		int INF = Integer.MAX_VALUE;
		Scanner sc = new Scanner(System.in);
		//char[] c = sc.next().toCharArray();
		//int N = A.length;
		int N = Integer.parseInt(sc.next());
		int[] P = new int[N];
		for(int i=0; i<N; i++){
			P[i] = Integer.parseInt(sc.next());
		}
		
		int ans = 0;
		
		for(int i=1;i<N-1;i++){
			if((P[i-1]>P[i] && P[i]>P[i+1])||(P[i-1]<P[i] && P[i]<P[i+1]))ans++;
		}
		
		System.out.println(ans);
		
	}
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (c/b);
	}
} public class Main {

	static long MOD = 1_000_000_007;
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		int INF = Integer.MAX_VALUE;
		Scanner sc = new Scanner(System.in);
		//char[] c = sc.next().toCharArray();
		//int N = A.length;
		int N = Integer.parseInt(sc.next());
		int[] P = new int[N];
		for(int i=0; i<N; i++){
			P[i] = Integer.parseInt(sc.next());
		}
		
		int ans = 0;
		
		for(int i=1;i<N-1;i++){
			if((P[i-1]>P[i] && P[i]>P[i+1])||(P[i-1]<P[i] && P[i]<P[i+1]))ans++;
		}
		
		System.out.println(ans);
		
	}
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (c/b);
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
 
 
public class Main {

	static long MOD = 1_000_000_007;
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		int INF = Integer.MAX_VALUE;
		Scanner sc = new Scanner(System.in);
		//char[] c = sc.next().toCharArray();
		//int N = A.length;
		int N = Integer.parseInt(sc.next());
		int[] P = new int[N];
		for(int i=0; i<N; i++){
			P[i] = Integer.parseInt(sc.next());
		}
		
		int ans = 0;
		
		for(int i=1;i<N-1;i++){
			if((P[i-1]>P[i] && P[i]>P[i+1])||(P[i-1]<P[i] && P[i]<P[i+1]))ans++;
		}
		
		System.out.println(ans);
		
	}
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (c/b);
	}
}

