import java.util.Scanner;

public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int[] p = new int[sc.nextInt()];

    for(int pIdx=0;pIdx<p.length;pIdx++){
      p[pIdx]=sc.nextInt();
    }

    int count=0;
    for(int pIdx = 1;pIdx<p.length-1;pIdx++){
      if(isMatch(p[pIdx-1],p[pIdx],p[pIdx+1]))count++;
    }
    System.out.println(count);
  }

  static boolean isMatch(int pm1, int p0, int pp1) {
    if(p0 < pm1 && p0 < pp1) return false;
    return !(p0 > pm1 && p0 > pp1);
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int[] p = new int[sc.nextInt()];

    for(int pIdx=0;pIdx<p.length;pIdx++){
      p[pIdx]=sc.nextInt();
    }

    int count=0;
    for(int pIdx = 1;pIdx<p.length-1;pIdx++){
      if(isMatch(p[pIdx-1],p[pIdx],p[pIdx+1]))count++;
    }
    System.out.println(count);
  }

  static boolean isMatch(int pm1, int p0, int pp1) {
    if(p0 < pm1 && p0 < pp1) return false;
    return !(p0 > pm1 && p0 > pp1);
  }
} Main public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int[] p = new int[sc.nextInt()];

    for(int pIdx=0;pIdx<p.length;pIdx++){
      p[pIdx]=sc.nextInt();
    }

    int count=0;
    for(int pIdx = 1;pIdx<p.length-1;pIdx++){
      if(isMatch(p[pIdx-1],p[pIdx],p[pIdx+1]))count++;
    }
    System.out.println(count);
  } main {

    Scanner sc = new Scanner(System.in);
    int[] p = new int[sc.nextInt()];

    for(int pIdx=0;pIdx<p.length;pIdx++){
      p[pIdx]=sc.nextInt();
    }

    int count=0;
    for(int pIdx = 1;pIdx<p.length-1;pIdx++){
      if(isMatch(p[pIdx-1],p[pIdx],p[pIdx+1]))count++;
    }
    System.out.println(count);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int[] p = new int[sc.nextInt()]; p new int[sc.nextInt()] sc.nextInt() sc.nextInt sc for(int pIdx=0;pIdx<p.length;pIdx++){
      p[pIdx]=sc.nextInt();
    } int pIdx=0; int pIdx=0; pIdx 0 pIdx<p.length pIdx p.length p p.length pIdx++ pIdx++ pIdx {
      p[pIdx]=sc.nextInt();
    } {
      p[pIdx]=sc.nextInt();
    } p[pIdx]=sc.nextInt() p[pIdx] p pIdx sc.nextInt() sc.nextInt sc int count=0; count 0 for(int pIdx = 1;pIdx<p.length-1;pIdx++){
      if(isMatch(p[pIdx-1],p[pIdx],p[pIdx+1]))count++;
    } int pIdx = 1; int pIdx = 1; pIdx 1 pIdx<p.length-1 pIdx p.length-1 p.length p p.length 1 pIdx++ pIdx++ pIdx {
      if(isMatch(p[pIdx-1],p[pIdx],p[pIdx+1]))count++;
    } {
      if(isMatch(p[pIdx-1],p[pIdx],p[pIdx+1]))count++;
    } if(isMatch(p[pIdx-1],p[pIdx],p[pIdx+1]))count++; isMatch(p[pIdx-1],p[pIdx],p[pIdx+1]) isMatch p[pIdx-1] p pIdx-1 pIdx 1 p[pIdx] p pIdx p[pIdx+1] p pIdx+1 pIdx 1 count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args static boolean isMatch(int pm1, int p0, int pp1) {
    if(p0 < pm1 && p0 < pp1) return false;
    return !(p0 > pm1 && p0 > pp1);
  } isMatch {
    if(p0 < pm1 && p0 < pp1) return false;
    return !(p0 > pm1 && p0 > pp1);
  } if(p0 < pm1 && p0 < pp1) return false; p0 < pm1 && p0 < pp1 p0 < pm1 p0 pm1 p0 < pp1 p0 pp1 return false; false return !(p0 > pm1 && p0 > pp1); !(p0 > pm1 && p0 > pp1) (p0 > pm1 && p0 > pp1) p0 > pm1 p0 pm1 p0 > pp1 p0 pp1 int pm1 pm1 int p0 p0 int pp1 pp1 public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int[] p = new int[sc.nextInt()];

    for(int pIdx=0;pIdx<p.length;pIdx++){
      p[pIdx]=sc.nextInt();
    }

    int count=0;
    for(int pIdx = 1;pIdx<p.length-1;pIdx++){
      if(isMatch(p[pIdx-1],p[pIdx],p[pIdx+1]))count++;
    }
    System.out.println(count);
  }

  static boolean isMatch(int pm1, int p0, int pp1) {
    if(p0 < pm1 && p0 < pp1) return false;
    return !(p0 > pm1 && p0 > pp1);
  }
} public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int[] p = new int[sc.nextInt()];

    for(int pIdx=0;pIdx<p.length;pIdx++){
      p[pIdx]=sc.nextInt();
    }

    int count=0;
    for(int pIdx = 1;pIdx<p.length-1;pIdx++){
      if(isMatch(p[pIdx-1],p[pIdx],p[pIdx+1]))count++;
    }
    System.out.println(count);
  }

  static boolean isMatch(int pm1, int p0, int pp1) {
    if(p0 < pm1 && p0 < pp1) return false;
    return !(p0 > pm1 && p0 > pp1);
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int[] p = new int[sc.nextInt()];

    for(int pIdx=0;pIdx<p.length;pIdx++){
      p[pIdx]=sc.nextInt();
    }

    int count=0;
    for(int pIdx = 1;pIdx<p.length-1;pIdx++){
      if(isMatch(p[pIdx-1],p[pIdx],p[pIdx+1]))count++;
    }
    System.out.println(count);
  }

  static boolean isMatch(int pm1, int p0, int pp1) {
    if(p0 < pm1 && p0 < pp1) return false;
    return !(p0 > pm1 && p0 > pp1);
  }
}
