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

public class Main {
	Scanner sc = new Scanner(System.in);
  	
	void b() {
		int n = sc.nextInt();
		int[] p = new int[n];
		int cnt = 0;
		for(int i = 0;i < n;i ++) {
			p[i] = sc.nextInt();
		}
		for(int i = 1;i < n - 1;i ++) {
			ArrayList<Integer> part = new ArrayList<>();
			part.add(p[i-1]); 
			part.add(p[i]);
			part.add(p[i+1]);
			part.sort(null);
			if(p[i] == part.get(1)) cnt++;
		}
		System.out.println(cnt);
	}
	
	public static void main(String[] args) {
		new Main().b();
	}

}


 import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
	Scanner sc = new Scanner(System.in);
  	
	void b() {
		int n = sc.nextInt();
		int[] p = new int[n];
		int cnt = 0;
		for(int i = 0;i < n;i ++) {
			p[i] = sc.nextInt();
		}
		for(int i = 1;i < n - 1;i ++) {
			ArrayList<Integer> part = new ArrayList<>();
			part.add(p[i-1]); 
			part.add(p[i]);
			part.add(p[i+1]);
			part.sort(null);
			if(p[i] == part.get(1)) cnt++;
		}
		System.out.println(cnt);
	}
	
	public static void main(String[] args) {
		new Main().b();
	}

} Main Scanner sc = new Scanner(System.in); sc new Scanner(System.in) void b() {
		int n = sc.nextInt();
		int[] p = new int[n];
		int cnt = 0;
		for(int i = 0;i < n;i ++) {
			p[i] = sc.nextInt();
		}
		for(int i = 1;i < n - 1;i ++) {
			ArrayList<Integer> part = new ArrayList<>();
			part.add(p[i-1]); 
			part.add(p[i]);
			part.add(p[i+1]);
			part.sort(null);
			if(p[i] == part.get(1)) cnt++;
		}
		System.out.println(cnt);
	} b {
		int n = sc.nextInt();
		int[] p = new int[n];
		int cnt = 0;
		for(int i = 0;i < n;i ++) {
			p[i] = sc.nextInt();
		}
		for(int i = 1;i < n - 1;i ++) {
			ArrayList<Integer> part = new ArrayList<>();
			part.add(p[i-1]); 
			part.add(p[i]);
			part.add(p[i+1]);
			part.sort(null);
			if(p[i] == part.get(1)) cnt++;
		}
		System.out.println(cnt);
	} int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] p = new int[n]; p new int[n] n int cnt = 0; cnt 0 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] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc for(int i = 1;i < n - 1;i ++) {
			ArrayList<Integer> part = new ArrayList<>();
			part.add(p[i-1]); 
			part.add(p[i]);
			part.add(p[i+1]);
			part.sort(null);
			if(p[i] == part.get(1)) cnt++;
		} int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i ++ i ++ i {
			ArrayList<Integer> part = new ArrayList<>();
			part.add(p[i-1]); 
			part.add(p[i]);
			part.add(p[i+1]);
			part.sort(null);
			if(p[i] == part.get(1)) cnt++;
		} {
			ArrayList<Integer> part = new ArrayList<>();
			part.add(p[i-1]); 
			part.add(p[i]);
			part.add(p[i+1]);
			part.sort(null);
			if(p[i] == part.get(1)) cnt++;
		} ArrayList<Integer> part = new ArrayList<>(); part new ArrayList<>() part.add(p[i-1]) part.add part p[i-1] p i-1 i 1 part.add(p[i]) part.add part p[i] p i part.add(p[i+1]) part.add part p[i+1] p i+1 i 1 part.sort(null) part.sort part null if(p[i] == part.get(1)) cnt++; p[i] == part.get(1) p[i] p i part.get(1) part.get part 1 cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt public static void main(String[] args) {
		new Main().b();
	} main {
		new Main().b();
	} new Main().b() new Main().b new Main() String[] args args public class Main {
	Scanner sc = new Scanner(System.in);
  	
	void b() {
		int n = sc.nextInt();
		int[] p = new int[n];
		int cnt = 0;
		for(int i = 0;i < n;i ++) {
			p[i] = sc.nextInt();
		}
		for(int i = 1;i < n - 1;i ++) {
			ArrayList<Integer> part = new ArrayList<>();
			part.add(p[i-1]); 
			part.add(p[i]);
			part.add(p[i+1]);
			part.sort(null);
			if(p[i] == part.get(1)) cnt++;
		}
		System.out.println(cnt);
	}
	
	public static void main(String[] args) {
		new Main().b();
	}

} public class Main {
	Scanner sc = new Scanner(System.in);
  	
	void b() {
		int n = sc.nextInt();
		int[] p = new int[n];
		int cnt = 0;
		for(int i = 0;i < n;i ++) {
			p[i] = sc.nextInt();
		}
		for(int i = 1;i < n - 1;i ++) {
			ArrayList<Integer> part = new ArrayList<>();
			part.add(p[i-1]); 
			part.add(p[i]);
			part.add(p[i+1]);
			part.sort(null);
			if(p[i] == part.get(1)) cnt++;
		}
		System.out.println(cnt);
	}
	
	public static void main(String[] args) {
		new Main().b();
	}

} Main
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
  	
	void b() {
		int n = sc.nextInt();
		int[] p = new int[n];
		int cnt = 0;
		for(int i = 0;i < n;i ++) {
			p[i] = sc.nextInt();
		}
		for(int i = 1;i < n - 1;i ++) {
			ArrayList<Integer> part = new ArrayList<>();
			part.add(p[i-1]); 
			part.add(p[i]);
			part.add(p[i+1]);
			part.sort(null);
			if(p[i] == part.get(1)) cnt++;
		}
		System.out.println(cnt);
	}
	
	public static void main(String[] args) {
		new Main().b();
	}

}



