import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int n = scan.nextInt();
      	int[] p = new int[n];
      	int counter = 0;
      	for(int i = 0; i < n ; i ++){
        	p[i] = scan.nextInt();
        }
      	for(int j = 0; j < n-2; j++){
        	int[] v = new int[3];
          	v[0] = p[j];
          	v[1] = p[j + 1];
          	v[2] = p[j + 2];
          	Arrays.sort(v);
          	if(v[1] == p[j + 1]){
            	counter++;
            }
         }
      	System.out.print(counter);
    }

} import java.util.*; util.* java public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int n = scan.nextInt();
      	int[] p = new int[n];
      	int counter = 0;
      	for(int i = 0; i < n ; i ++){
        	p[i] = scan.nextInt();
        }
      	for(int j = 0; j < n-2; j++){
        	int[] v = new int[3];
          	v[0] = p[j];
          	v[1] = p[j + 1];
          	v[2] = p[j + 2];
          	Arrays.sort(v);
          	if(v[1] == p[j + 1]){
            	counter++;
            }
         }
      	System.out.print(counter);
    }

} Main public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int n = scan.nextInt();
      	int[] p = new int[n];
      	int counter = 0;
      	for(int i = 0; i < n ; i ++){
        	p[i] = scan.nextInt();
        }
      	for(int j = 0; j < n-2; j++){
        	int[] v = new int[3];
          	v[0] = p[j];
          	v[1] = p[j + 1];
          	v[2] = p[j + 2];
          	Arrays.sort(v);
          	if(v[1] == p[j + 1]){
            	counter++;
            }
         }
      	System.out.print(counter);
    } main {
    	Scanner scan = new Scanner(System.in);
      	int n = scan.nextInt();
      	int[] p = new int[n];
      	int counter = 0;
      	for(int i = 0; i < n ; i ++){
        	p[i] = scan.nextInt();
        }
      	for(int j = 0; j < n-2; j++){
        	int[] v = new int[3];
          	v[0] = p[j];
          	v[1] = p[j + 1];
          	v[2] = p[j + 2];
          	Arrays.sort(v);
          	if(v[1] == p[j + 1]){
            	counter++;
            }
         }
      	System.out.print(counter);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] p = new int[n]; p new int[n] n int counter = 0; counter 0 for(int i = 0; i < n ; i ++){
        	p[i] = scan.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i ++ i ++ i {
        	p[i] = scan.nextInt();
        } {
        	p[i] = scan.nextInt();
        } p[i] = scan.nextInt() p[i] p i scan.nextInt() scan.nextInt scan for(int j = 0; j < n-2; j++){
        	int[] v = new int[3];
          	v[0] = p[j];
          	v[1] = p[j + 1];
          	v[2] = p[j + 2];
          	Arrays.sort(v);
          	if(v[1] == p[j + 1]){
            	counter++;
            }
         } int j = 0; int j = 0; j 0 j < n-2 j n-2 n 2 j++ j++ j {
        	int[] v = new int[3];
          	v[0] = p[j];
          	v[1] = p[j + 1];
          	v[2] = p[j + 2];
          	Arrays.sort(v);
          	if(v[1] == p[j + 1]){
            	counter++;
            }
         } {
        	int[] v = new int[3];
          	v[0] = p[j];
          	v[1] = p[j + 1];
          	v[2] = p[j + 2];
          	Arrays.sort(v);
          	if(v[1] == p[j + 1]){
            	counter++;
            }
         } int[] v = new int[3]; v new int[3] 3 v[0] = p[j] v[0] v 0 p[j] p j v[1] = p[j + 1] v[1] v 1 p[j + 1] p j + 1 j 1 v[2] = p[j + 2] v[2] v 2 p[j + 2] p j + 2 j 2 Arrays.sort(v) Arrays.sort Arrays v if(v[1] == p[j + 1]){
            	counter++;
            } v[1] == p[j + 1] v[1] v 1 p[j + 1] p j + 1 j 1 {
            	counter++;
            } counter++ counter System.out.print(counter) System.out.print System.out System System.out counter String[] args args public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int n = scan.nextInt();
      	int[] p = new int[n];
      	int counter = 0;
      	for(int i = 0; i < n ; i ++){
        	p[i] = scan.nextInt();
        }
      	for(int j = 0; j < n-2; j++){
        	int[] v = new int[3];
          	v[0] = p[j];
          	v[1] = p[j + 1];
          	v[2] = p[j + 2];
          	Arrays.sort(v);
          	if(v[1] == p[j + 1]){
            	counter++;
            }
         }
      	System.out.print(counter);
    }

} public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int n = scan.nextInt();
      	int[] p = new int[n];
      	int counter = 0;
      	for(int i = 0; i < n ; i ++){
        	p[i] = scan.nextInt();
        }
      	for(int j = 0; j < n-2; j++){
        	int[] v = new int[3];
          	v[0] = p[j];
          	v[1] = p[j + 1];
          	v[2] = p[j + 2];
          	Arrays.sort(v);
          	if(v[1] == p[j + 1]){
            	counter++;
            }
         }
      	System.out.print(counter);
    }

} Main
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int n = scan.nextInt();
      	int[] p = new int[n];
      	int counter = 0;
      	for(int i = 0; i < n ; i ++){
        	p[i] = scan.nextInt();
        }
      	for(int j = 0; j < n-2; j++){
        	int[] v = new int[3];
          	v[0] = p[j];
          	v[1] = p[j + 1];
          	v[2] = p[j + 2];
          	Arrays.sort(v);
          	if(v[1] == p[j + 1]){
            	counter++;
            }
         }
      	System.out.print(counter);
    }

}