import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int N = sc.nextInt();
		
		int[] d = new int[N];
		for (int i = 0; i < N; i++) {
			d[i] = sc.nextInt();
		}
        int ans = 0;
        for (int i = 0; i < N-2; i++) {
        int l = d[i];
        int m = d[i+1];
        int r = d[i+2];        
        if(((l > m) && (m > r)) || ((l < m) && (m < r))){
          ans++;
        }
        }
		System.out.println(ans);
	}		
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int N = sc.nextInt();
		
		int[] d = new int[N];
		for (int i = 0; i < N; i++) {
			d[i] = sc.nextInt();
		}
        int ans = 0;
        for (int i = 0; i < N-2; i++) {
        int l = d[i];
        int m = d[i+1];
        int r = d[i+2];        
        if(((l > m) && (m > r)) || ((l < m) && (m < r))){
          ans++;
        }
        }
		System.out.println(ans);
	}		
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int N = sc.nextInt();
		
		int[] d = new int[N];
		for (int i = 0; i < N; i++) {
			d[i] = sc.nextInt();
		}
        int ans = 0;
        for (int i = 0; i < N-2; i++) {
        int l = d[i];
        int m = d[i+1];
        int r = d[i+2];        
        if(((l > m) && (m > r)) || ((l < m) && (m < r))){
          ans++;
        }
        }
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int N = sc.nextInt();
		
		int[] d = new int[N];
		for (int i = 0; i < N; i++) {
			d[i] = sc.nextInt();
		}
        int ans = 0;
        for (int i = 0; i < N-2; i++) {
        int l = d[i];
        int m = d[i+1];
        int r = d[i+2];        
        if(((l > m) && (m > r)) || ((l < m) && (m < r))){
          ans++;
        }
        }
		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] d = new int[N]; d new int[N] N for (int i = 0; i < N; i++) {
			d[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			d[i] = sc.nextInt();
		} {
			d[i] = sc.nextInt();
		} d[i] = sc.nextInt() d[i] d i sc.nextInt() sc.nextInt sc int ans = 0; ans 0 for (int i = 0; i < N-2; i++) {
        int l = d[i];
        int m = d[i+1];
        int r = d[i+2];        
        if(((l > m) && (m > r)) || ((l < m) && (m < r))){
          ans++;
        }
        } int i = 0; int i = 0; i 0 i < N-2 i N-2 N 2 i++ i++ i {
        int l = d[i];
        int m = d[i+1];
        int r = d[i+2];        
        if(((l > m) && (m > r)) || ((l < m) && (m < r))){
          ans++;
        }
        } {
        int l = d[i];
        int m = d[i+1];
        int r = d[i+2];        
        if(((l > m) && (m > r)) || ((l < m) && (m < r))){
          ans++;
        }
        } int l = d[i]; l d[i] d i int m = d[i+1]; m d[i+1] d i+1 i 1 int r = d[i+2]; r d[i+2] d i+2 i 2 if(((l > m) && (m > r)) || ((l < m) && (m < r))){
          ans++;
        } ((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 {
          ans++;
        } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int N = sc.nextInt();
		
		int[] d = new int[N];
		for (int i = 0; i < N; i++) {
			d[i] = sc.nextInt();
		}
        int ans = 0;
        for (int i = 0; i < N-2; i++) {
        int l = d[i];
        int m = d[i+1];
        int r = d[i+2];        
        if(((l > m) && (m > r)) || ((l < m) && (m < r))){
          ans++;
        }
        }
		System.out.println(ans);
	}		
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int N = sc.nextInt();
		
		int[] d = new int[N];
		for (int i = 0; i < N; i++) {
			d[i] = sc.nextInt();
		}
        int ans = 0;
        for (int i = 0; i < N-2; i++) {
        int l = d[i];
        int m = d[i+1];
        int r = d[i+2];        
        if(((l > m) && (m > r)) || ((l < m) && (m < r))){
          ans++;
        }
        }
		System.out.println(ans);
	}		
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int N = sc.nextInt();
		
		int[] d = new int[N];
		for (int i = 0; i < N; i++) {
			d[i] = sc.nextInt();
		}
        int ans = 0;
        for (int i = 0; i < N-2; i++) {
        int l = d[i];
        int m = d[i+1];
        int r = d[i+2];        
        if(((l > m) && (m > r)) || ((l < m) && (m < r))){
          ans++;
        }
        }
		System.out.println(ans);
	}		
}
