import java.util.*;
public class Main
{
	public static void main(String[] args) {
	    Scanner read = new Scanner(System.in);
	    int n = read.nextInt();
	    int x[] = new int[n];
	    for(int i=0; i<n; i++){
	        x[i] = read.nextInt();
	    }
	    int c = 0;
	    for(int i=0; i<n; i++){
	        if (i == 0 || i == n-1){
	            continue;
	        }else if((x[i] < x[i-1] && x[i] > x[i+1]) || (x[i] < x[i+1] && x[i] > x[i-1])){
	            c++;
	        }
	    }
		System.out.println(c);
	}
} import java.util.*; util.* java public class Main
{
	public static void main(String[] args) {
	    Scanner read = new Scanner(System.in);
	    int n = read.nextInt();
	    int x[] = new int[n];
	    for(int i=0; i<n; i++){
	        x[i] = read.nextInt();
	    }
	    int c = 0;
	    for(int i=0; i<n; i++){
	        if (i == 0 || i == n-1){
	            continue;
	        }else if((x[i] < x[i-1] && x[i] > x[i+1]) || (x[i] < x[i+1] && x[i] > x[i-1])){
	            c++;
	        }
	    }
		System.out.println(c);
	}
} Main public static void main(String[] args) {
	    Scanner read = new Scanner(System.in);
	    int n = read.nextInt();
	    int x[] = new int[n];
	    for(int i=0; i<n; i++){
	        x[i] = read.nextInt();
	    }
	    int c = 0;
	    for(int i=0; i<n; i++){
	        if (i == 0 || i == n-1){
	            continue;
	        }else if((x[i] < x[i-1] && x[i] > x[i+1]) || (x[i] < x[i+1] && x[i] > x[i-1])){
	            c++;
	        }
	    }
		System.out.println(c);
	} main {
	    Scanner read = new Scanner(System.in);
	    int n = read.nextInt();
	    int x[] = new int[n];
	    for(int i=0; i<n; i++){
	        x[i] = read.nextInt();
	    }
	    int c = 0;
	    for(int i=0; i<n; i++){
	        if (i == 0 || i == n-1){
	            continue;
	        }else if((x[i] < x[i-1] && x[i] > x[i+1]) || (x[i] < x[i+1] && x[i] > x[i-1])){
	            c++;
	        }
	    }
		System.out.println(c);
	} Scanner read = new Scanner(System.in); read new Scanner(System.in) int n = read.nextInt(); n read.nextInt() read.nextInt read int x[] = new int[n]; x new int[n] n for(int i=0; i<n; i++){
	        x[i] = read.nextInt();
	    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
	        x[i] = read.nextInt();
	    } {
	        x[i] = read.nextInt();
	    } x[i] = read.nextInt() x[i] x i read.nextInt() read.nextInt read int c = 0; c 0 for(int i=0; i<n; i++){
	        if (i == 0 || i == n-1){
	            continue;
	        }else if((x[i] < x[i-1] && x[i] > x[i+1]) || (x[i] < x[i+1] && x[i] > x[i-1])){
	            c++;
	        }
	    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
	        if (i == 0 || i == n-1){
	            continue;
	        }else if((x[i] < x[i-1] && x[i] > x[i+1]) || (x[i] < x[i+1] && x[i] > x[i-1])){
	            c++;
	        }
	    } {
	        if (i == 0 || i == n-1){
	            continue;
	        }else if((x[i] < x[i-1] && x[i] > x[i+1]) || (x[i] < x[i+1] && x[i] > x[i-1])){
	            c++;
	        }
	    } if (i == 0 || i == n-1){
	            continue;
	        }else if((x[i] < x[i-1] && x[i] > x[i+1]) || (x[i] < x[i+1] && x[i] > x[i-1])){
	            c++;
	        } i == 0 || i == n-1 i == 0 i 0 i == n-1 i n-1 n 1 {
	            continue;
	        } continue; if((x[i] < x[i-1] && x[i] > x[i+1]) || (x[i] < x[i+1] && x[i] > x[i-1])){
	            c++;
	        } (x[i] < x[i-1] && x[i] > x[i+1]) || (x[i] < x[i+1] && x[i] > x[i-1]) (x[i] < x[i-1] && x[i] > x[i+1]) x[i] < x[i-1] x[i] x i x[i-1] x i-1 i 1 x[i] > x[i+1] x[i] x i x[i+1] x i+1 i 1 (x[i] < x[i+1] && x[i] > x[i-1]) x[i] < x[i+1] x[i] x i x[i+1] x i+1 i 1 x[i] > x[i-1] x[i] x i x[i-1] x i-1 i 1 {
	            c++;
	        } c++ c System.out.println(c) System.out.println System.out System System.out c String[] args args public class Main
{
	public static void main(String[] args) {
	    Scanner read = new Scanner(System.in);
	    int n = read.nextInt();
	    int x[] = new int[n];
	    for(int i=0; i<n; i++){
	        x[i] = read.nextInt();
	    }
	    int c = 0;
	    for(int i=0; i<n; i++){
	        if (i == 0 || i == n-1){
	            continue;
	        }else if((x[i] < x[i-1] && x[i] > x[i+1]) || (x[i] < x[i+1] && x[i] > x[i-1])){
	            c++;
	        }
	    }
		System.out.println(c);
	}
} public class Main
{
	public static void main(String[] args) {
	    Scanner read = new Scanner(System.in);
	    int n = read.nextInt();
	    int x[] = new int[n];
	    for(int i=0; i<n; i++){
	        x[i] = read.nextInt();
	    }
	    int c = 0;
	    for(int i=0; i<n; i++){
	        if (i == 0 || i == n-1){
	            continue;
	        }else if((x[i] < x[i-1] && x[i] > x[i+1]) || (x[i] < x[i+1] && x[i] > x[i-1])){
	            c++;
	        }
	    }
		System.out.println(c);
	}
} Main
import java.util.*;
public class Main
{
	public static void main(String[] args) {
	    Scanner read = new Scanner(System.in);
	    int n = read.nextInt();
	    int x[] = new int[n];
	    for(int i=0; i<n; i++){
	        x[i] = read.nextInt();
	    }
	    int c = 0;
	    for(int i=0; i<n; i++){
	        if (i == 0 || i == n-1){
	            continue;
	        }else if((x[i] < x[i-1] && x[i] > x[i+1]) || (x[i] < x[i+1] && x[i] > x[i-1])){
	            c++;
	        }
	    }
		System.out.println(c);
	}
}