import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		InputReader in = new InputReader();
		int n = in.nextInt();
		
		int[] arr = new int[n];
		for (int i=0; i<n; i++) {
			arr[i] = in.nextInt();
		}
		
		int res = 0;
		for (int i=1; i<n-1; i++) {
			ArrayList<Integer> list = new ArrayList<>();
			list.add(arr[i]);
			list.add(arr[i-1]);
			list.add(arr[i+1]);
			Collections.sort(list);
			if (list.get(list.size()-2) == arr[i])
				++res;
		}
		
		System.out.println(res);
	}

	static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;
		
		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}
		
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
	
	public static void main(String[] args) {
		InputReader in = new InputReader();
		int n = in.nextInt();
		
		int[] arr = new int[n];
		for (int i=0; i<n; i++) {
			arr[i] = in.nextInt();
		}
		
		int res = 0;
		for (int i=1; i<n-1; i++) {
			ArrayList<Integer> list = new ArrayList<>();
			list.add(arr[i]);
			list.add(arr[i-1]);
			list.add(arr[i+1]);
			Collections.sort(list);
			if (list.get(list.size()-2) == arr[i])
				++res;
		}
		
		System.out.println(res);
	}

	static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;
		
		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}
		
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
} Main public static void main(String[] args) {
		InputReader in = new InputReader();
		int n = in.nextInt();
		
		int[] arr = new int[n];
		for (int i=0; i<n; i++) {
			arr[i] = in.nextInt();
		}
		
		int res = 0;
		for (int i=1; i<n-1; i++) {
			ArrayList<Integer> list = new ArrayList<>();
			list.add(arr[i]);
			list.add(arr[i-1]);
			list.add(arr[i+1]);
			Collections.sort(list);
			if (list.get(list.size()-2) == arr[i])
				++res;
		}
		
		System.out.println(res);
	} main {
		InputReader in = new InputReader();
		int n = in.nextInt();
		
		int[] arr = new int[n];
		for (int i=0; i<n; i++) {
			arr[i] = in.nextInt();
		}
		
		int res = 0;
		for (int i=1; i<n-1; i++) {
			ArrayList<Integer> list = new ArrayList<>();
			list.add(arr[i]);
			list.add(arr[i-1]);
			list.add(arr[i+1]);
			Collections.sort(list);
			if (list.get(list.size()-2) == arr[i])
				++res;
		}
		
		System.out.println(res);
	} InputReader in = new InputReader(); in new InputReader() int n = in.nextInt(); n in.nextInt() in.nextInt in int[] arr = new int[n]; arr new int[n] n for (int i=0; i<n; i++) {
			arr[i] = in.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			arr[i] = in.nextInt();
		} {
			arr[i] = in.nextInt();
		} arr[i] = in.nextInt() arr[i] arr i in.nextInt() in.nextInt in int res = 0; res 0 for (int i=1; i<n-1; i++) {
			ArrayList<Integer> list = new ArrayList<>();
			list.add(arr[i]);
			list.add(arr[i-1]);
			list.add(arr[i+1]);
			Collections.sort(list);
			if (list.get(list.size()-2) == arr[i])
				++res;
		} int i=1; int i=1; i 1 i<n-1 i n-1 n 1 i++ i++ i {
			ArrayList<Integer> list = new ArrayList<>();
			list.add(arr[i]);
			list.add(arr[i-1]);
			list.add(arr[i+1]);
			Collections.sort(list);
			if (list.get(list.size()-2) == arr[i])
				++res;
		} {
			ArrayList<Integer> list = new ArrayList<>();
			list.add(arr[i]);
			list.add(arr[i-1]);
			list.add(arr[i+1]);
			Collections.sort(list);
			if (list.get(list.size()-2) == arr[i])
				++res;
		} ArrayList<Integer> list = new ArrayList<>(); list new ArrayList<>() list.add(arr[i]) list.add list arr[i] arr i list.add(arr[i-1]) list.add list arr[i-1] arr i-1 i 1 list.add(arr[i+1]) list.add list arr[i+1] arr i+1 i 1 Collections.sort(list) Collections.sort Collections list if (list.get(list.size()-2) == arr[i])
				++res; list.get(list.size()-2) == arr[i] list.get(list.size()-2) list.get list list.size()-2 list.size() list.size list 2 arr[i] arr i ++res res System.out.println(res) System.out.println System.out System System.out res String[] args args static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;
		
		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}
		
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
	} InputReader public BufferedReader br; br public StringTokenizer st; st public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		} InputReader {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		} br = new BufferedReader(new InputStreamReader(System.in)) br new BufferedReader(new InputStreamReader(System.in)) st = null st null public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		} next {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		} while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			} st == null || !st.hasMoreTokens() st == null st null !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			} try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				} catch (IOException e) {
					throw new RuntimeException(e);
				} IOException e {
					throw new RuntimeException(e);
				} throw new RuntimeException(e); new RuntimeException(e) {
					st = new StringTokenizer(br.readLine());
				} st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st public int nextInt() {
			return Integer.parseInt(next());
		} nextInt {
			return Integer.parseInt(next());
		} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public class Main {
	
	public static void main(String[] args) {
		InputReader in = new InputReader();
		int n = in.nextInt();
		
		int[] arr = new int[n];
		for (int i=0; i<n; i++) {
			arr[i] = in.nextInt();
		}
		
		int res = 0;
		for (int i=1; i<n-1; i++) {
			ArrayList<Integer> list = new ArrayList<>();
			list.add(arr[i]);
			list.add(arr[i-1]);
			list.add(arr[i+1]);
			Collections.sort(list);
			if (list.get(list.size()-2) == arr[i])
				++res;
		}
		
		System.out.println(res);
	}

	static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;
		
		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}
		
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
} public class Main {
	
	public static void main(String[] args) {
		InputReader in = new InputReader();
		int n = in.nextInt();
		
		int[] arr = new int[n];
		for (int i=0; i<n; i++) {
			arr[i] = in.nextInt();
		}
		
		int res = 0;
		for (int i=1; i<n-1; i++) {
			ArrayList<Integer> list = new ArrayList<>();
			list.add(arr[i]);
			list.add(arr[i-1]);
			list.add(arr[i+1]);
			Collections.sort(list);
			if (list.get(list.size()-2) == arr[i])
				++res;
		}
		
		System.out.println(res);
	}

	static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;
		
		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}
		
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
} Main
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		InputReader in = new InputReader();
		int n = in.nextInt();
		
		int[] arr = new int[n];
		for (int i=0; i<n; i++) {
			arr[i] = in.nextInt();
		}
		
		int res = 0;
		for (int i=1; i<n-1; i++) {
			ArrayList<Integer> list = new ArrayList<>();
			list.add(arr[i]);
			list.add(arr[i-1]);
			list.add(arr[i+1]);
			Collections.sort(list);
			if (list.get(list.size()-2) == arr[i])
				++res;
		}
		
		System.out.println(res);
	}

	static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;
		
		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}
		
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}