import java.util.Scanner;
public class Main {
	
		static void solve() {
			Scanner sc =new Scanner(System.in);
			int n = sc.nextInt();
			int array[] = new int[n];
			int res = 0;
			for(int i = 0;i <n;i++) {
				array[i]=sc.nextInt();
			}
			for(int i = 1;i <n-1;i++) {
				if(array[i]<array[i-1]&&array[i]>array[i+1]||array[i]<array[i+1]&&array[i]>array[i-1]) {
					res++;
				}
			}
			System.out.println(res);
			sc.close();
		}
	public static void main(String[] args) {
		solve();

	}

} import java.util.Scanner; Scanner java.util public class Main {
	
		static void solve() {
			Scanner sc =new Scanner(System.in);
			int n = sc.nextInt();
			int array[] = new int[n];
			int res = 0;
			for(int i = 0;i <n;i++) {
				array[i]=sc.nextInt();
			}
			for(int i = 1;i <n-1;i++) {
				if(array[i]<array[i-1]&&array[i]>array[i+1]||array[i]<array[i+1]&&array[i]>array[i-1]) {
					res++;
				}
			}
			System.out.println(res);
			sc.close();
		}
	public static void main(String[] args) {
		solve();

	}

} Main static void solve() {
			Scanner sc =new Scanner(System.in);
			int n = sc.nextInt();
			int array[] = new int[n];
			int res = 0;
			for(int i = 0;i <n;i++) {
				array[i]=sc.nextInt();
			}
			for(int i = 1;i <n-1;i++) {
				if(array[i]<array[i-1]&&array[i]>array[i+1]||array[i]<array[i+1]&&array[i]>array[i-1]) {
					res++;
				}
			}
			System.out.println(res);
			sc.close();
		} solve {
			Scanner sc =new Scanner(System.in);
			int n = sc.nextInt();
			int array[] = new int[n];
			int res = 0;
			for(int i = 0;i <n;i++) {
				array[i]=sc.nextInt();
			}
			for(int i = 1;i <n-1;i++) {
				if(array[i]<array[i-1]&&array[i]>array[i+1]||array[i]<array[i+1]&&array[i]>array[i-1]) {
					res++;
				}
			}
			System.out.println(res);
			sc.close();
		} Scanner sc =new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int array[] = new int[n]; array new int[n] n int res = 0; res 0 for(int i = 0;i <n;i++) {
				array[i]=sc.nextInt();
			} int i = 0; int i = 0; i 0 i <n i n i++ i++ i {
				array[i]=sc.nextInt();
			} {
				array[i]=sc.nextInt();
			} array[i]=sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc for(int i = 1;i <n-1;i++) {
				if(array[i]<array[i-1]&&array[i]>array[i+1]||array[i]<array[i+1]&&array[i]>array[i-1]) {
					res++;
				}
			} int i = 1; int i = 1; i 1 i <n-1 i n-1 n 1 i++ i++ i {
				if(array[i]<array[i-1]&&array[i]>array[i+1]||array[i]<array[i+1]&&array[i]>array[i-1]) {
					res++;
				}
			} {
				if(array[i]<array[i-1]&&array[i]>array[i+1]||array[i]<array[i+1]&&array[i]>array[i-1]) {
					res++;
				}
			} if(array[i]<array[i-1]&&array[i]>array[i+1]||array[i]<array[i+1]&&array[i]>array[i-1]) {
					res++;
				} array[i]<array[i-1]&&array[i]>array[i+1]||array[i]<array[i+1]&&array[i]>array[i-1] array[i]<array[i-1]&&array[i]>array[i+1] array[i]<array[i-1] array[i] array i array[i-1] array i-1 i 1 array[i]>array[i+1] array[i] array i array[i+1] array i+1 i 1 array[i]<array[i+1]&&array[i]>array[i-1] array[i]<array[i+1] array[i] array i array[i+1] array i+1 i 1 array[i]>array[i-1] array[i] array i array[i-1] array i-1 i 1 {
					res++;
				} res++ res System.out.println(res) System.out.println System.out System System.out res sc.close() sc.close sc public static void main(String[] args) {
		solve();

	} main {
		solve();

	} solve() solve String[] args args public class Main {
	
		static void solve() {
			Scanner sc =new Scanner(System.in);
			int n = sc.nextInt();
			int array[] = new int[n];
			int res = 0;
			for(int i = 0;i <n;i++) {
				array[i]=sc.nextInt();
			}
			for(int i = 1;i <n-1;i++) {
				if(array[i]<array[i-1]&&array[i]>array[i+1]||array[i]<array[i+1]&&array[i]>array[i-1]) {
					res++;
				}
			}
			System.out.println(res);
			sc.close();
		}
	public static void main(String[] args) {
		solve();

	}

} public class Main {
	
		static void solve() {
			Scanner sc =new Scanner(System.in);
			int n = sc.nextInt();
			int array[] = new int[n];
			int res = 0;
			for(int i = 0;i <n;i++) {
				array[i]=sc.nextInt();
			}
			for(int i = 1;i <n-1;i++) {
				if(array[i]<array[i-1]&&array[i]>array[i+1]||array[i]<array[i+1]&&array[i]>array[i-1]) {
					res++;
				}
			}
			System.out.println(res);
			sc.close();
		}
	public static void main(String[] args) {
		solve();

	}

} Main
import java.util.Scanner;
public class Main {
	
		static void solve() {
			Scanner sc =new Scanner(System.in);
			int n = sc.nextInt();
			int array[] = new int[n];
			int res = 0;
			for(int i = 0;i <n;i++) {
				array[i]=sc.nextInt();
			}
			for(int i = 1;i <n-1;i++) {
				if(array[i]<array[i-1]&&array[i]>array[i+1]||array[i]<array[i+1]&&array[i]>array[i-1]) {
					res++;
				}
			}
			System.out.println(res);
			sc.close();
		}
	public static void main(String[] args) {
		solve();

	}

}
