import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		solver.readP(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public void readP(String str) {
		String[] strArr = str.split("\\s+");
		int cnt = 0;
		for (int i = 1; i < N - 1; i++) {
			int a = Integer.parseInt(strArr[i - 1]);
			int b = Integer.parseInt(strArr[i]);
			int c = Integer.parseInt(strArr[i + 1]);
			if ((a < b && b < c) || (a > b && b > c))
				cnt++;
		}
		System.out.println(cnt);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		solver.readP(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
} Main public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		solver.readP(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	} main {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		solver.readP(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	} BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) Solver solver = new Solver(); solver new Solver() solver.init() solver.init solver solver.readHead(in.readLine()) solver.readHead solver in.readLine() in.readLine in solver.readP(in.readLine()) solver.readP solver in.readLine() in.readLine in String args[] args class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public void readP(String str) {
		String[] strArr = str.split("\\s+");
		int cnt = 0;
		for (int i = 1; i < N - 1; i++) {
			int a = Integer.parseInt(strArr[i - 1]);
			int b = Integer.parseInt(strArr[i]);
			int c = Integer.parseInt(strArr[i + 1]);
			if ((a < b && b < c) || (a > b && b > c))
				cnt++;
		}
		System.out.println(cnt);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
} Solver int N; N int cnt; cnt public void init() {
		N = 0;
		cnt = 0;
	} init {
		N = 0;
		cnt = 0;
	} N = 0 N 0 cnt = 0 cnt 0 public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	} readHead {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	} String[] strArr = str.split("\\s+"); strArr str.split("\\s+") str.split str "\\s+" N = Integer.parseInt(strArr[0]) N Integer.parseInt(strArr[0]) Integer.parseInt Integer strArr[0] strArr 0 String str str public void readP(String str) {
		String[] strArr = str.split("\\s+");
		int cnt = 0;
		for (int i = 1; i < N - 1; i++) {
			int a = Integer.parseInt(strArr[i - 1]);
			int b = Integer.parseInt(strArr[i]);
			int c = Integer.parseInt(strArr[i + 1]);
			if ((a < b && b < c) || (a > b && b > c))
				cnt++;
		}
		System.out.println(cnt);
	} readP {
		String[] strArr = str.split("\\s+");
		int cnt = 0;
		for (int i = 1; i < N - 1; i++) {
			int a = Integer.parseInt(strArr[i - 1]);
			int b = Integer.parseInt(strArr[i]);
			int c = Integer.parseInt(strArr[i + 1]);
			if ((a < b && b < c) || (a > b && b > c))
				cnt++;
		}
		System.out.println(cnt);
	} String[] strArr = str.split("\\s+"); strArr str.split("\\s+") str.split str "\\s+" int cnt = 0; cnt 0 for (int i = 1; i < N - 1; i++) {
			int a = Integer.parseInt(strArr[i - 1]);
			int b = Integer.parseInt(strArr[i]);
			int c = Integer.parseInt(strArr[i + 1]);
			if ((a < b && b < c) || (a > b && b > c))
				cnt++;
		} int i = 1; int i = 1; i 1 i < N - 1 i N - 1 N 1 i++ i++ i {
			int a = Integer.parseInt(strArr[i - 1]);
			int b = Integer.parseInt(strArr[i]);
			int c = Integer.parseInt(strArr[i + 1]);
			if ((a < b && b < c) || (a > b && b > c))
				cnt++;
		} {
			int a = Integer.parseInt(strArr[i - 1]);
			int b = Integer.parseInt(strArr[i]);
			int c = Integer.parseInt(strArr[i + 1]);
			if ((a < b && b < c) || (a > b && b > c))
				cnt++;
		} int a = Integer.parseInt(strArr[i - 1]); a Integer.parseInt(strArr[i - 1]) Integer.parseInt Integer strArr[i - 1] strArr i - 1 i 1 int b = Integer.parseInt(strArr[i]); b Integer.parseInt(strArr[i]) Integer.parseInt Integer strArr[i] strArr i int c = Integer.parseInt(strArr[i + 1]); c Integer.parseInt(strArr[i + 1]) Integer.parseInt Integer strArr[i + 1] strArr i + 1 i 1 if ((a < b && b < c) || (a > b && b > c))
				cnt++; (a < b && b < c) || (a > b && b > c) (a < b && b < c) a < b a b b < c b c (a > b && b > c) a > b a b b > c b c cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String str str public boolean hasNext() {
		return cnt < N;
	} hasNext {
		return cnt < N;
	} return cnt < N; cnt < N cnt N public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	} readBody {
		// System.out.println(str);
		cnt++;
	} cnt++ cnt String str str public void solve() {

	} solve {

	}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		solver.readP(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public void readP(String str) {
		String[] strArr = str.split("\\s+");
		int cnt = 0;
		for (int i = 1; i < N - 1; i++) {
			int a = Integer.parseInt(strArr[i - 1]);
			int b = Integer.parseInt(strArr[i]);
			int c = Integer.parseInt(strArr[i + 1]);
			if ((a < b && b < c) || (a > b && b > c))
				cnt++;
		}
		System.out.println(cnt);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}
