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

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int result = 0;

		String str[] = br.readLine().split(" ");
		int list[] = new int[n];

		for (int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(str[i]);
		}

		for (int i = 1; i < n - 1; i++) {
			if (list[i - 1] < list[i] && list[i] < list[i + 1]) {
				result++;
			} else if (list[i - 1] > list[i] && list[i] > list[i + 1]) {
				result++;
			}
		}
		System.out.println(result);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int result = 0;

		String str[] = br.readLine().split(" ");
		int list[] = new int[n];

		for (int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(str[i]);
		}

		for (int i = 1; i < n - 1; i++) {
			if (list[i - 1] < list[i] && list[i] < list[i + 1]) {
				result++;
			} else if (list[i - 1] > list[i] && list[i] > list[i + 1]) {
				result++;
			}
		}
		System.out.println(result);
	}
} Main public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int result = 0;

		String str[] = br.readLine().split(" ");
		int list[] = new int[n];

		for (int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(str[i]);
		}

		for (int i = 1; i < n - 1; i++) {
			if (list[i - 1] < list[i] && list[i] < list[i + 1]) {
				result++;
			} else if (list[i - 1] > list[i] && list[i] > list[i + 1]) {
				result++;
			}
		}
		System.out.println(result);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int result = 0;

		String str[] = br.readLine().split(" ");
		int list[] = new int[n];

		for (int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(str[i]);
		}

		for (int i = 1; i < n - 1; i++) {
			if (list[i - 1] < list[i] && list[i] < list[i + 1]) {
				result++;
			} else if (list[i - 1] > list[i] && list[i] > list[i + 1]) {
				result++;
			}
		}
		System.out.println(result);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int result = 0; result 0 String str[] = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int list[] = new int[n]; list new int[n] n for (int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(str[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			list[i] = Integer.parseInt(str[i]);
		} {
			list[i] = Integer.parseInt(str[i]);
		} list[i] = Integer.parseInt(str[i]) list[i] list i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i for (int i = 1; i < n - 1; i++) {
			if (list[i - 1] < list[i] && list[i] < list[i + 1]) {
				result++;
			} else if (list[i - 1] > list[i] && list[i] > list[i + 1]) {
				result++;
			}
		} int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i {
			if (list[i - 1] < list[i] && list[i] < list[i + 1]) {
				result++;
			} else if (list[i - 1] > list[i] && list[i] > list[i + 1]) {
				result++;
			}
		} {
			if (list[i - 1] < list[i] && list[i] < list[i + 1]) {
				result++;
			} else if (list[i - 1] > list[i] && list[i] > list[i + 1]) {
				result++;
			}
		} if (list[i - 1] < list[i] && list[i] < list[i + 1]) {
				result++;
			} else if (list[i - 1] > list[i] && list[i] > list[i + 1]) {
				result++;
			} list[i - 1] < list[i] && list[i] < list[i + 1] list[i - 1] < list[i] list[i - 1] list i - 1 i 1 list[i] list i list[i] < list[i + 1] list[i] list i list[i + 1] list i + 1 i 1 {
				result++;
			} result++ result if (list[i - 1] > list[i] && list[i] > list[i + 1]) {
				result++;
			} list[i - 1] > list[i] && list[i] > list[i + 1] list[i - 1] > list[i] list[i - 1] list i - 1 i 1 list[i] list i list[i] > list[i + 1] list[i] list i list[i + 1] list i + 1 i 1 {
				result++;
			} result++ result System.out.println(result) System.out.println System.out System System.out result String args[] args public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int result = 0;

		String str[] = br.readLine().split(" ");
		int list[] = new int[n];

		for (int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(str[i]);
		}

		for (int i = 1; i < n - 1; i++) {
			if (list[i - 1] < list[i] && list[i] < list[i + 1]) {
				result++;
			} else if (list[i - 1] > list[i] && list[i] > list[i + 1]) {
				result++;
			}
		}
		System.out.println(result);
	}
} public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int result = 0;

		String str[] = br.readLine().split(" ");
		int list[] = new int[n];

		for (int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(str[i]);
		}

		for (int i = 1; i < n - 1; i++) {
			if (list[i - 1] < list[i] && list[i] < list[i + 1]) {
				result++;
			} else if (list[i - 1] > list[i] && list[i] > list[i + 1]) {
				result++;
			}
		}
		System.out.println(result);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		int result = 0;

		String str[] = br.readLine().split(" ");
		int list[] = new int[n];

		for (int i = 0; i < n; i++) {
			list[i] = Integer.parseInt(str[i]);
		}

		for (int i = 1; i < n - 1; i++) {
			if (list[i - 1] < list[i] && list[i] < list[i + 1]) {
				result++;
			} else if (list[i - 1] > list[i] && list[i] > list[i + 1]) {
				result++;
			}
		}
		System.out.println(result);
	}
}