import java.util.Scanner;
import java.util.Arrays;

public class Main{
  static int judge(int a, int b, int c){
    if(a>b && b>c){
      return 1;
    }else if(a<b && b<c){
      return 1;
    }else{
      return 0;
    }
  }



  public  static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] array = new int[n];

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    }
    for(int j=1; j<n-1; j++){
      count += judge(array[j-1],array[j],array[j+1]);
    }

    System.out.println(count);
  }
} import java.util.Scanner; Scanner java.util import java.util.Arrays; Arrays java.util public class Main{
  static int judge(int a, int b, int c){
    if(a>b && b>c){
      return 1;
    }else if(a<b && b<c){
      return 1;
    }else{
      return 0;
    }
  }



  public  static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] array = new int[n];

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    }
    for(int j=1; j<n-1; j++){
      count += judge(array[j-1],array[j],array[j+1]);
    }

    System.out.println(count);
  }
} Main static int judge(int a, int b, int c){
    if(a>b && b>c){
      return 1;
    }else if(a<b && b<c){
      return 1;
    }else{
      return 0;
    }
  } judge {
    if(a>b && b>c){
      return 1;
    }else if(a<b && b<c){
      return 1;
    }else{
      return 0;
    }
  } if(a>b && b>c){
      return 1;
    }else if(a<b && b<c){
      return 1;
    }else{
      return 0;
    } a>b && b>c a>b a b b>c b c {
      return 1;
    } return 1; 1 if(a<b && b<c){
      return 1;
    }else{
      return 0;
    } a<b && b<c a<b a b b<c b c {
      return 1;
    } return 1; 1 {
      return 0;
    } return 0; 0 int a a int b b int c c public  static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] array = new int[n];

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    }
    for(int j=1; j<n-1; j++){
      count += judge(array[j-1],array[j],array[j+1]);
    }

    System.out.println(count);
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] array = new int[n];

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    }
    for(int j=1; j<n-1; j++){
      count += judge(array[j-1],array[j],array[j+1]);
    }

    System.out.println(count);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int count = 0; count 0 int[] array = new int[n]; array new int[n] n 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 j=1; j<n-1; j++){
      count += judge(array[j-1],array[j],array[j+1]);
    } int j=1; int j=1; j 1 j<n-1 j n-1 n 1 j++ j++ j {
      count += judge(array[j-1],array[j],array[j+1]);
    } {
      count += judge(array[j-1],array[j],array[j+1]);
    } count += judge(array[j-1],array[j],array[j+1]) count judge(array[j-1],array[j],array[j+1]) judge array[j-1] array j-1 j 1 array[j] array j array[j+1] array j+1 j 1 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main{
  static int judge(int a, int b, int c){
    if(a>b && b>c){
      return 1;
    }else if(a<b && b<c){
      return 1;
    }else{
      return 0;
    }
  }



  public  static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] array = new int[n];

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    }
    for(int j=1; j<n-1; j++){
      count += judge(array[j-1],array[j],array[j+1]);
    }

    System.out.println(count);
  }
} public class Main{
  static int judge(int a, int b, int c){
    if(a>b && b>c){
      return 1;
    }else if(a<b && b<c){
      return 1;
    }else{
      return 0;
    }
  }



  public  static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] array = new int[n];

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    }
    for(int j=1; j<n-1; j++){
      count += judge(array[j-1],array[j],array[j+1]);
    }

    System.out.println(count);
  }
} Main
import java.util.Scanner;
import java.util.Arrays;

public class Main{
  static int judge(int a, int b, int c){
    if(a>b && b>c){
      return 1;
    }else if(a<b && b<c){
      return 1;
    }else{
      return 0;
    }
  }



  public  static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] array = new int[n];

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
    }
    for(int j=1; j<n-1; j++){
      count += judge(array[j-1],array[j],array[j+1]);
    }

    System.out.println(count);
  }
}