import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int[] p = new int[n];
		int idx;
		for (idx = 0; idx < n; idx++) {
			p[idx] = Integer.parseInt(sc.next());
		}

		int cnt = 0;
		for (idx = 1; idx < n - 1; idx++) {
			if (p[idx] <= p[idx - 1]) {
				if (p[idx] > p[idx + 1]) {
					++cnt;
				}
			} else { //if (p[idx] > p[idx -1]) {
				if (p[idx] <= p[idx + 1]) {
					++cnt;
				}
			}
		}

		System.out.println(cnt);

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int[] p = new int[n];
		int idx;
		for (idx = 0; idx < n; idx++) {
			p[idx] = Integer.parseInt(sc.next());
		}

		int cnt = 0;
		for (idx = 1; idx < n - 1; idx++) {
			if (p[idx] <= p[idx - 1]) {
				if (p[idx] > p[idx + 1]) {
					++cnt;
				}
			} else { //if (p[idx] > p[idx -1]) {
				if (p[idx] <= p[idx + 1]) {
					++cnt;
				}
			}
		}

		System.out.println(cnt);

	}

} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int[] p = new int[n];
		int idx;
		for (idx = 0; idx < n; idx++) {
			p[idx] = Integer.parseInt(sc.next());
		}

		int cnt = 0;
		for (idx = 1; idx < n - 1; idx++) {
			if (p[idx] <= p[idx - 1]) {
				if (p[idx] > p[idx + 1]) {
					++cnt;
				}
			} else { //if (p[idx] > p[idx -1]) {
				if (p[idx] <= p[idx + 1]) {
					++cnt;
				}
			}
		}

		System.out.println(cnt);

	} main {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int[] p = new int[n];
		int idx;
		for (idx = 0; idx < n; idx++) {
			p[idx] = Integer.parseInt(sc.next());
		}

		int cnt = 0;
		for (idx = 1; idx < n - 1; idx++) {
			if (p[idx] <= p[idx - 1]) {
				if (p[idx] > p[idx + 1]) {
					++cnt;
				}
			} else { //if (p[idx] > p[idx -1]) {
				if (p[idx] <= p[idx + 1]) {
					++cnt;
				}
			}
		}

		System.out.println(cnt);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] p = new int[n]; p new int[n] n int idx; idx for (idx = 0; idx < n; idx++) {
			p[idx] = Integer.parseInt(sc.next());
		} idx = 0; idx = 0 idx 0 idx < n idx n idx++ idx++ idx {
			p[idx] = Integer.parseInt(sc.next());
		} {
			p[idx] = Integer.parseInt(sc.next());
		} p[idx] = Integer.parseInt(sc.next()) p[idx] p idx Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int cnt = 0; cnt 0 for (idx = 1; idx < n - 1; idx++) {
			if (p[idx] <= p[idx - 1]) {
				if (p[idx] > p[idx + 1]) {
					++cnt;
				}
			} else { //if (p[idx] > p[idx -1]) {
				if (p[idx] <= p[idx + 1]) {
					++cnt;
				}
			}
		} idx = 1; idx = 1 idx 1 idx < n - 1 idx n - 1 n 1 idx++ idx++ idx {
			if (p[idx] <= p[idx - 1]) {
				if (p[idx] > p[idx + 1]) {
					++cnt;
				}
			} else { //if (p[idx] > p[idx -1]) {
				if (p[idx] <= p[idx + 1]) {
					++cnt;
				}
			}
		} {
			if (p[idx] <= p[idx - 1]) {
				if (p[idx] > p[idx + 1]) {
					++cnt;
				}
			} else { //if (p[idx] > p[idx -1]) {
				if (p[idx] <= p[idx + 1]) {
					++cnt;
				}
			}
		} if (p[idx] <= p[idx - 1]) {
				if (p[idx] > p[idx + 1]) {
					++cnt;
				}
			} else { //if (p[idx] > p[idx -1]) {
				if (p[idx] <= p[idx + 1]) {
					++cnt;
				}
			} p[idx] <= p[idx - 1] p[idx] p idx p[idx - 1] p idx - 1 idx 1 {
				if (p[idx] > p[idx + 1]) {
					++cnt;
				}
			} if (p[idx] > p[idx + 1]) {
					++cnt;
				} p[idx] > p[idx + 1] p[idx] p idx p[idx + 1] p idx + 1 idx 1 {
					++cnt;
				} ++cnt cnt { //if (p[idx] > p[idx -1]) {
				if (p[idx] <= p[idx + 1]) {
					++cnt;
				}
			} if (p[idx] <= p[idx + 1]) {
					++cnt;
				} p[idx] <= p[idx + 1] p[idx] p idx p[idx + 1] p idx + 1 idx 1 {
					++cnt;
				} ++cnt cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int[] p = new int[n];
		int idx;
		for (idx = 0; idx < n; idx++) {
			p[idx] = Integer.parseInt(sc.next());
		}

		int cnt = 0;
		for (idx = 1; idx < n - 1; idx++) {
			if (p[idx] <= p[idx - 1]) {
				if (p[idx] > p[idx + 1]) {
					++cnt;
				}
			} else { //if (p[idx] > p[idx -1]) {
				if (p[idx] <= p[idx + 1]) {
					++cnt;
				}
			}
		}

		System.out.println(cnt);

	}

} public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int[] p = new int[n];
		int idx;
		for (idx = 0; idx < n; idx++) {
			p[idx] = Integer.parseInt(sc.next());
		}

		int cnt = 0;
		for (idx = 1; idx < n - 1; idx++) {
			if (p[idx] <= p[idx - 1]) {
				if (p[idx] > p[idx + 1]) {
					++cnt;
				}
			} else { //if (p[idx] > p[idx -1]) {
				if (p[idx] <= p[idx + 1]) {
					++cnt;
				}
			}
		}

		System.out.println(cnt);

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int[] p = new int[n];
		int idx;
		for (idx = 0; idx < n; idx++) {
			p[idx] = Integer.parseInt(sc.next());
		}

		int cnt = 0;
		for (idx = 1; idx < n - 1; idx++) {
			if (p[idx] <= p[idx - 1]) {
				if (p[idx] > p[idx + 1]) {
					++cnt;
				}
			} else { //if (p[idx] > p[idx -1]) {
				if (p[idx] <= p[idx + 1]) {
					++cnt;
				}
			}
		}

		System.out.println(cnt);

	}

}
