import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int p[] = new int[n];
		int ans = 0;
		for(int i = 0; i < n; i++){
			p[i] = stdIn.nextInt();
		}
		for(int i = 0; i < n - 2; i++){
			if(p[i] < p[i+1] && p[i+1] < p[i+2] || p[i] > p[i+1] && p[i+1] > p[i+2]){
				ans++;
			}
		}
		System.out.println(ans);
		stdIn.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int p[] = new int[n];
		int ans = 0;
		for(int i = 0; i < n; i++){
			p[i] = stdIn.nextInt();
		}
		for(int i = 0; i < n - 2; i++){
			if(p[i] < p[i+1] && p[i+1] < p[i+2] || p[i] > p[i+1] && p[i+1] > p[i+2]){
				ans++;
			}
		}
		System.out.println(ans);
		stdIn.close();
	}
} Main public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int p[] = new int[n];
		int ans = 0;
		for(int i = 0; i < n; i++){
			p[i] = stdIn.nextInt();
		}
		for(int i = 0; i < n - 2; i++){
			if(p[i] < p[i+1] && p[i+1] < p[i+2] || p[i] > p[i+1] && p[i+1] > p[i+2]){
				ans++;
			}
		}
		System.out.println(ans);
		stdIn.close();
	} main {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int p[] = new int[n];
		int ans = 0;
		for(int i = 0; i < n; i++){
			p[i] = stdIn.nextInt();
		}
		for(int i = 0; i < n - 2; i++){
			if(p[i] < p[i+1] && p[i+1] < p[i+2] || p[i] > p[i+1] && p[i+1] > p[i+2]){
				ans++;
			}
		}
		System.out.println(ans);
		stdIn.close();
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int p[] = new int[n]; p new int[n] n int ans = 0; ans 0 for(int i = 0; i < n; i++){
			p[i] = stdIn.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			p[i] = stdIn.nextInt();
		} {
			p[i] = stdIn.nextInt();
		} p[i] = stdIn.nextInt() p[i] p i stdIn.nextInt() stdIn.nextInt stdIn for(int i = 0; i < n - 2; i++){
			if(p[i] < p[i+1] && p[i+1] < p[i+2] || p[i] > p[i+1] && p[i+1] > p[i+2]){
				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] > p[i+1] && p[i+1] > p[i+2]){
				ans++;
			}
		} {
			if(p[i] < p[i+1] && p[i+1] < p[i+2] || p[i] > p[i+1] && p[i+1] > p[i+2]){
				ans++;
			}
		} if(p[i] < p[i+1] && p[i+1] < p[i+2] || p[i] > p[i+1] && p[i+1] > p[i+2]){
				ans++;
			} p[i] < p[i+1] && p[i+1] < p[i+2] || p[i] > p[i+1] && p[i+1] > p[i+2] 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] > 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 {
				ans++;
			} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans stdIn.close() stdIn.close stdIn String[] args args public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int p[] = new int[n];
		int ans = 0;
		for(int i = 0; i < n; i++){
			p[i] = stdIn.nextInt();
		}
		for(int i = 0; i < n - 2; i++){
			if(p[i] < p[i+1] && p[i+1] < p[i+2] || p[i] > p[i+1] && p[i+1] > p[i+2]){
				ans++;
			}
		}
		System.out.println(ans);
		stdIn.close();
	}
} public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int p[] = new int[n];
		int ans = 0;
		for(int i = 0; i < n; i++){
			p[i] = stdIn.nextInt();
		}
		for(int i = 0; i < n - 2; i++){
			if(p[i] < p[i+1] && p[i+1] < p[i+2] || p[i] > p[i+1] && p[i+1] > p[i+2]){
				ans++;
			}
		}
		System.out.println(ans);
		stdIn.close();
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int p[] = new int[n];
		int ans = 0;
		for(int i = 0; i < n; i++){
			p[i] = stdIn.nextInt();
		}
		for(int i = 0; i < n - 2; i++){
			if(p[i] < p[i+1] && p[i+1] < p[i+2] || p[i] > p[i+1] && p[i+1] > p[i+2]){
				ans++;
			}
		}
		System.out.println(ans);
		stdIn.close();
	}
}