import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] ary = new int[n];
    for(int c = 0;c<n;c++){
      ary[c] = sc.nextInt();
    }
    for(int c = 1;c<n-1;c++){
      if(ary[c]>ary[c-1]&&ary[c+1]>ary[c]){
        count++;
      }else if(ary[c+1]<ary[c]&&ary[c]<ary[c-1]){
        count++;
      }
    }
    System.out.println(count);
  } 
} 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 count = 0;
    int[] ary = new int[n];
    for(int c = 0;c<n;c++){
      ary[c] = sc.nextInt();
    }
    for(int c = 1;c<n-1;c++){
      if(ary[c]>ary[c-1]&&ary[c+1]>ary[c]){
        count++;
      }else if(ary[c+1]<ary[c]&&ary[c]<ary[c-1]){
        count++;
      }
    }
    System.out.println(count);
  } 
} Main public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] ary = new int[n];
    for(int c = 0;c<n;c++){
      ary[c] = sc.nextInt();
    }
    for(int c = 1;c<n-1;c++){
      if(ary[c]>ary[c-1]&&ary[c+1]>ary[c]){
        count++;
      }else if(ary[c+1]<ary[c]&&ary[c]<ary[c-1]){
        count++;
      }
    }
    System.out.println(count);
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] ary = new int[n];
    for(int c = 0;c<n;c++){
      ary[c] = sc.nextInt();
    }
    for(int c = 1;c<n-1;c++){
      if(ary[c]>ary[c-1]&&ary[c+1]>ary[c]){
        count++;
      }else if(ary[c+1]<ary[c]&&ary[c]<ary[c-1]){
        count++;
      }
    }
    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[] ary = new int[n]; ary new int[n] n for(int c = 0;c<n;c++){
      ary[c] = sc.nextInt();
    } int c = 0; int c = 0; c 0 c<n c n c++ c++ c {
      ary[c] = sc.nextInt();
    } {
      ary[c] = sc.nextInt();
    } ary[c] = sc.nextInt() ary[c] ary c sc.nextInt() sc.nextInt sc for(int c = 1;c<n-1;c++){
      if(ary[c]>ary[c-1]&&ary[c+1]>ary[c]){
        count++;
      }else if(ary[c+1]<ary[c]&&ary[c]<ary[c-1]){
        count++;
      }
    } int c = 1; int c = 1; c 1 c<n-1 c n-1 n 1 c++ c++ c {
      if(ary[c]>ary[c-1]&&ary[c+1]>ary[c]){
        count++;
      }else if(ary[c+1]<ary[c]&&ary[c]<ary[c-1]){
        count++;
      }
    } {
      if(ary[c]>ary[c-1]&&ary[c+1]>ary[c]){
        count++;
      }else if(ary[c+1]<ary[c]&&ary[c]<ary[c-1]){
        count++;
      }
    } if(ary[c]>ary[c-1]&&ary[c+1]>ary[c]){
        count++;
      }else if(ary[c+1]<ary[c]&&ary[c]<ary[c-1]){
        count++;
      } ary[c]>ary[c-1]&&ary[c+1]>ary[c] ary[c]>ary[c-1] ary[c] ary c ary[c-1] ary c-1 c 1 ary[c+1]>ary[c] ary[c+1] ary c+1 c 1 ary[c] ary c {
        count++;
      } count++ count if(ary[c+1]<ary[c]&&ary[c]<ary[c-1]){
        count++;
      } ary[c+1]<ary[c]&&ary[c]<ary[c-1] ary[c+1]<ary[c] ary[c+1] ary c+1 c 1 ary[c] ary c ary[c]<ary[c-1] ary[c] ary c ary[c-1] ary c-1 c 1 {
        count++;
      } count++ count System.out.println(count) System.out.println System.out System System.out count String args[] args public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] ary = new int[n];
    for(int c = 0;c<n;c++){
      ary[c] = sc.nextInt();
    }
    for(int c = 1;c<n-1;c++){
      if(ary[c]>ary[c-1]&&ary[c+1]>ary[c]){
        count++;
      }else if(ary[c+1]<ary[c]&&ary[c]<ary[c-1]){
        count++;
      }
    }
    System.out.println(count);
  } 
} public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] ary = new int[n];
    for(int c = 0;c<n;c++){
      ary[c] = sc.nextInt();
    }
    for(int c = 1;c<n-1;c++){
      if(ary[c]>ary[c-1]&&ary[c+1]>ary[c]){
        count++;
      }else if(ary[c+1]<ary[c]&&ary[c]<ary[c-1]){
        count++;
      }
    }
    System.out.println(count);
  } 
} Main
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] ary = new int[n];
    for(int c = 0;c<n;c++){
      ary[c] = sc.nextInt();
    }
    for(int c = 1;c<n-1;c++){
      if(ary[c]>ary[c-1]&&ary[c+1]>ary[c]){
        count++;
      }else if(ary[c+1]<ary[c]&&ary[c]<ary[c-1]){
        count++;
      }
    }
    System.out.println(count);
  } 
}