import java.util.*;
import java.io.*;

class Main {

	void solve() {

		int n = inint();
		int[] ar = inintar(n);
		int count = 0;
		
		for (int i=0; i<n-2; i++) {
			if (check(ar[i], ar[i+1], ar[i+2]) == true) count++;
		}
		
		out.println(count);

	}
	
	public boolean check(int L, int M, int R) {
		if ((L > M && M > R) || (L < M && M < R)) return true;
		else return false;
	}
	

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}

	public String instr() {
		return in.next();
	}

	public char inchar() {
		return in.next().charAt(0);
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

} import java.util.*; util.* java import java.io.*; io.* java class Main {

	void solve() {

		int n = inint();
		int[] ar = inintar(n);
		int count = 0;
		
		for (int i=0; i<n-2; i++) {
			if (check(ar[i], ar[i+1], ar[i+2]) == true) count++;
		}
		
		out.println(count);

	}
	
	public boolean check(int L, int M, int R) {
		if ((L > M && M > R) || (L < M && M < R)) return true;
		else return false;
	}
	

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}

	public String instr() {
		return in.next();
	}

	public char inchar() {
		return in.next().charAt(0);
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

} Main public static Scanner in = new Scanner(System.in); in new Scanner(System.in) public static PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) void solve() {

		int n = inint();
		int[] ar = inintar(n);
		int count = 0;
		
		for (int i=0; i<n-2; i++) {
			if (check(ar[i], ar[i+1], ar[i+2]) == true) count++;
		}
		
		out.println(count);

	} solve {

		int n = inint();
		int[] ar = inintar(n);
		int count = 0;
		
		for (int i=0; i<n-2; i++) {
			if (check(ar[i], ar[i+1], ar[i+2]) == true) count++;
		}
		
		out.println(count);

	} int n = inint(); n inint() inint int[] ar = inintar(n); ar inintar(n) inintar n int count = 0; count 0 for (int i=0; i<n-2; i++) {
			if (check(ar[i], ar[i+1], ar[i+2]) == true) count++;
		} int i=0; int i=0; i 0 i<n-2 i n-2 n 2 i++ i++ i {
			if (check(ar[i], ar[i+1], ar[i+2]) == true) count++;
		} {
			if (check(ar[i], ar[i+1], ar[i+2]) == true) count++;
		} if (check(ar[i], ar[i+1], ar[i+2]) == true) count++; check(ar[i], ar[i+1], ar[i+2]) == true check(ar[i], ar[i+1], ar[i+2]) check ar[i] ar i ar[i+1] ar i+1 i 1 ar[i+2] ar i+2 i 2 true count++ count out.println(count) out.println out count public boolean check(int L, int M, int R) {
		if ((L > M && M > R) || (L < M && M < R)) return true;
		else return false;
	} check {
		if ((L > M && M > R) || (L < M && M < R)) return true;
		else return false;
	} if ((L > M && M > R) || (L < M && M < R)) return true;
		else return false; (L > M && M > R) || (L < M && M < R) (L > M && M > R) L > M L M M > R M R (L < M && M < R) L < M L M M < R M R return true; true return false; false int L L int M M int R R public static void main(String[] args) {
		new Main().solve();
		out.flush();
	} main {
		new Main().solve();
		out.flush();
	} new Main().solve() new Main().solve new Main() out.flush() out.flush out String[] args args public int inint() {
		return in.nextInt();
	} inint {
		return in.nextInt();
	} return in.nextInt(); in.nextInt() in.nextInt in public long inlong() {
		return in.nextLong();
	} inlong {
		return in.nextLong();
	} return in.nextLong(); in.nextLong() in.nextLong in public String instr() {
		return in.next();
	} instr {
		return in.next();
	} return in.next(); in.next() in.next in public char inchar() {
		return in.next().charAt(0);
	} inchar {
		return in.next().charAt(0);
	} return in.next().charAt(0); in.next().charAt(0) in.next().charAt in.next() in.next in 0 public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	} inintar {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	} int[] a = new int[num]; a new int[num] num for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		} int i=0; int i=0; i 0 i<num i num i++ i++ i {
			a[i] = in.nextInt();
		} {
			a[i] = in.nextInt();
		} a[i] = in.nextInt() a[i] a i in.nextInt() in.nextInt in return a; a int num num public char[] incharar() {
		return in.next().toCharArray();
	} incharar {
		return in.next().toCharArray();
	} return in.next().toCharArray(); in.next().toCharArray() in.next().toCharArray in.next() in.next in
import java.util.*;
import java.io.*;

class Main {

	void solve() {

		int n = inint();
		int[] ar = inintar(n);
		int count = 0;
		
		for (int i=0; i<n-2; i++) {
			if (check(ar[i], ar[i+1], ar[i+2]) == true) count++;
		}
		
		out.println(count);

	}
	
	public boolean check(int L, int M, int R) {
		if ((L > M && M > R) || (L < M && M < R)) return true;
		else return false;
	}
	

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}

	public String instr() {
		return in.next();
	}

	public char inchar() {
		return in.next().charAt(0);
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

}