import java.util.Scanner;

public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner (System.in);
		
		int N = sc.nextInt();
		
		int[] list = new int [N];
		
		for (int index=0; index<N; index++){
		    list[index]=sc.nextInt();
		}

        int count = 0;
        
		for (int index=1; index<N-1; index++){
		    if (list[index]<list[index+1]&&list[index]>list[index-1]){
		        count++;
		    } else if (list[index]>list[index+1]&&list[index]<list[index-1]){
		        count ++;
		    }
		}
		
		System.out.println(count);

		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner (System.in);
		
		int N = sc.nextInt();
		
		int[] list = new int [N];
		
		for (int index=0; index<N; index++){
		    list[index]=sc.nextInt();
		}

        int count = 0;
        
		for (int index=1; index<N-1; index++){
		    if (list[index]<list[index+1]&&list[index]>list[index-1]){
		        count++;
		    } else if (list[index]>list[index+1]&&list[index]<list[index-1]){
		        count ++;
		    }
		}
		
		System.out.println(count);

		sc.close();
	}
} Main public static void main (String[] args) {

		Scanner sc = new Scanner (System.in);
		
		int N = sc.nextInt();
		
		int[] list = new int [N];
		
		for (int index=0; index<N; index++){
		    list[index]=sc.nextInt();
		}

        int count = 0;
        
		for (int index=1; index<N-1; index++){
		    if (list[index]<list[index+1]&&list[index]>list[index-1]){
		        count++;
		    } else if (list[index]>list[index+1]&&list[index]<list[index-1]){
		        count ++;
		    }
		}
		
		System.out.println(count);

		sc.close();
	} main {

		Scanner sc = new Scanner (System.in);
		
		int N = sc.nextInt();
		
		int[] list = new int [N];
		
		for (int index=0; index<N; index++){
		    list[index]=sc.nextInt();
		}

        int count = 0;
        
		for (int index=1; index<N-1; index++){
		    if (list[index]<list[index+1]&&list[index]>list[index-1]){
		        count++;
		    } else if (list[index]>list[index+1]&&list[index]<list[index-1]){
		        count ++;
		    }
		}
		
		System.out.println(count);

		sc.close();
	} Scanner sc = new Scanner (System.in); sc new Scanner (System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] list = new int [N]; list new int [N] N for (int index=0; index<N; index++){
		    list[index]=sc.nextInt();
		} int index=0; int index=0; index 0 index<N index N index++ index++ index {
		    list[index]=sc.nextInt();
		} {
		    list[index]=sc.nextInt();
		} list[index]=sc.nextInt() list[index] list index sc.nextInt() sc.nextInt sc int count = 0; count 0 for (int index=1; index<N-1; index++){
		    if (list[index]<list[index+1]&&list[index]>list[index-1]){
		        count++;
		    } else if (list[index]>list[index+1]&&list[index]<list[index-1]){
		        count ++;
		    }
		} int index=1; int index=1; index 1 index<N-1 index N-1 N 1 index++ index++ index {
		    if (list[index]<list[index+1]&&list[index]>list[index-1]){
		        count++;
		    } else if (list[index]>list[index+1]&&list[index]<list[index-1]){
		        count ++;
		    }
		} {
		    if (list[index]<list[index+1]&&list[index]>list[index-1]){
		        count++;
		    } else if (list[index]>list[index+1]&&list[index]<list[index-1]){
		        count ++;
		    }
		} if (list[index]<list[index+1]&&list[index]>list[index-1]){
		        count++;
		    } else if (list[index]>list[index+1]&&list[index]<list[index-1]){
		        count ++;
		    } list[index]<list[index+1]&&list[index]>list[index-1] list[index]<list[index+1] list[index] list index list[index+1] list index+1 index 1 list[index]>list[index-1] list[index] list index list[index-1] list index-1 index 1 {
		        count++;
		    } count++ count if (list[index]>list[index+1]&&list[index]<list[index-1]){
		        count ++;
		    } list[index]>list[index+1]&&list[index]<list[index-1] list[index]>list[index+1] list[index] list index list[index+1] list index+1 index 1 list[index]<list[index-1] list[index] list index list[index-1] list index-1 index 1 {
		        count ++;
		    } count ++ count System.out.println(count) System.out.println System.out System System.out count sc.close() sc.close sc String[] args args public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner (System.in);
		
		int N = sc.nextInt();
		
		int[] list = new int [N];
		
		for (int index=0; index<N; index++){
		    list[index]=sc.nextInt();
		}

        int count = 0;
        
		for (int index=1; index<N-1; index++){
		    if (list[index]<list[index+1]&&list[index]>list[index-1]){
		        count++;
		    } else if (list[index]>list[index+1]&&list[index]<list[index-1]){
		        count ++;
		    }
		}
		
		System.out.println(count);

		sc.close();
	}
} public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner (System.in);
		
		int N = sc.nextInt();
		
		int[] list = new int [N];
		
		for (int index=0; index<N; index++){
		    list[index]=sc.nextInt();
		}

        int count = 0;
        
		for (int index=1; index<N-1; index++){
		    if (list[index]<list[index+1]&&list[index]>list[index-1]){
		        count++;
		    } else if (list[index]>list[index+1]&&list[index]<list[index-1]){
		        count ++;
		    }
		}
		
		System.out.println(count);

		sc.close();
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner (System.in);
		
		int N = sc.nextInt();
		
		int[] list = new int [N];
		
		for (int index=0; index<N; index++){
		    list[index]=sc.nextInt();
		}

        int count = 0;
        
		for (int index=1; index<N-1; index++){
		    if (list[index]<list[index+1]&&list[index]>list[index-1]){
		        count++;
		    } else if (list[index]>list[index+1]&&list[index]<list[index-1]){
		        count ++;
		    }
		}
		
		System.out.println(count);

		sc.close();
	}
}