import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int t1 = scan.nextInt();
    int t2 = scan.nextInt();
    int t3;
    int count = 0;
    for (int i = 2; i < n; i++) {
      t3 = scan.nextInt();
      if (judge(t1, t2, t3)) {
        count++;
      }
      t1 = t2;
      t2 = t3;
    }
    System.out.println(count);
  }

  private static boolean judge(int t1, int t2, int t3) {
    return (t1 < t2 && t2 < t3) || (t3 < t2 && t2 < t1);
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int t1 = scan.nextInt();
    int t2 = scan.nextInt();
    int t3;
    int count = 0;
    for (int i = 2; i < n; i++) {
      t3 = scan.nextInt();
      if (judge(t1, t2, t3)) {
        count++;
      }
      t1 = t2;
      t2 = t3;
    }
    System.out.println(count);
  }

  private static boolean judge(int t1, int t2, int t3) {
    return (t1 < t2 && t2 < t3) || (t3 < t2 && t2 < t1);
  }
} Main public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int t1 = scan.nextInt();
    int t2 = scan.nextInt();
    int t3;
    int count = 0;
    for (int i = 2; i < n; i++) {
      t3 = scan.nextInt();
      if (judge(t1, t2, t3)) {
        count++;
      }
      t1 = t2;
      t2 = t3;
    }
    System.out.println(count);
  } main {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int t1 = scan.nextInt();
    int t2 = scan.nextInt();
    int t3;
    int count = 0;
    for (int i = 2; i < n; i++) {
      t3 = scan.nextInt();
      if (judge(t1, t2, t3)) {
        count++;
      }
      t1 = t2;
      t2 = t3;
    }
    System.out.println(count);
  } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int t1 = scan.nextInt(); t1 scan.nextInt() scan.nextInt scan int t2 = scan.nextInt(); t2 scan.nextInt() scan.nextInt scan int t3; t3 int count = 0; count 0 for (int i = 2; i < n; i++) {
      t3 = scan.nextInt();
      if (judge(t1, t2, t3)) {
        count++;
      }
      t1 = t2;
      t2 = t3;
    } int i = 2; int i = 2; i 2 i < n i n i++ i++ i {
      t3 = scan.nextInt();
      if (judge(t1, t2, t3)) {
        count++;
      }
      t1 = t2;
      t2 = t3;
    } {
      t3 = scan.nextInt();
      if (judge(t1, t2, t3)) {
        count++;
      }
      t1 = t2;
      t2 = t3;
    } t3 = scan.nextInt() t3 scan.nextInt() scan.nextInt scan if (judge(t1, t2, t3)) {
        count++;
      } judge(t1, t2, t3) judge t1 t2 t3 {
        count++;
      } count++ count t1 = t2 t1 t2 t2 = t3 t2 t3 System.out.println(count) System.out.println System.out System System.out count String[] args args private static boolean judge(int t1, int t2, int t3) {
    return (t1 < t2 && t2 < t3) || (t3 < t2 && t2 < t1);
  } judge {
    return (t1 < t2 && t2 < t3) || (t3 < t2 && t2 < t1);
  } return (t1 < t2 && t2 < t3) || (t3 < t2 && t2 < t1); (t1 < t2 && t2 < t3) || (t3 < t2 && t2 < t1) (t1 < t2 && t2 < t3) t1 < t2 t1 t2 t2 < t3 t2 t3 (t3 < t2 && t2 < t1) t3 < t2 t3 t2 t2 < t1 t2 t1 int t1 t1 int t2 t2 int t3 t3 public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int t1 = scan.nextInt();
    int t2 = scan.nextInt();
    int t3;
    int count = 0;
    for (int i = 2; i < n; i++) {
      t3 = scan.nextInt();
      if (judge(t1, t2, t3)) {
        count++;
      }
      t1 = t2;
      t2 = t3;
    }
    System.out.println(count);
  }

  private static boolean judge(int t1, int t2, int t3) {
    return (t1 < t2 && t2 < t3) || (t3 < t2 && t2 < t1);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int t1 = scan.nextInt();
    int t2 = scan.nextInt();
    int t3;
    int count = 0;
    for (int i = 2; i < n; i++) {
      t3 = scan.nextInt();
      if (judge(t1, t2, t3)) {
        count++;
      }
      t1 = t2;
      t2 = t3;
    }
    System.out.println(count);
  }

  private static boolean judge(int t1, int t2, int t3) {
    return (t1 < t2 && t2 < t3) || (t3 < t2 && t2 < t1);
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int t1 = scan.nextInt();
    int t2 = scan.nextInt();
    int t3;
    int count = 0;
    for (int i = 2; i < n; i++) {
      t3 = scan.nextInt();
      if (judge(t1, t2, t3)) {
        count++;
      }
      t1 = t2;
      t2 = t3;
    }
    System.out.println(count);
  }

  private static boolean judge(int t1, int t2, int t3) {
    return (t1 < t2 && t2 < t3) || (t3 < t2 && t2 < t1);
  }
}
