import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int n = in.nextInt();
      int[] p = new int[n];

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

      int count = 0;
      for (int i = 1; i < p.length - 1; ++i) {
        int max = Math.max(p[i - 1], Math.max(p[i], p[i + 1]));
        int min = Math.min(p[i - 1], Math.min(p[i], p[i + 1]));

        if (p[i] < max && p[i] > min) {
          ++count;
        }
      }

      System.out.println(count);
    }
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int n = in.nextInt();
      int[] p = new int[n];

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

      int count = 0;
      for (int i = 1; i < p.length - 1; ++i) {
        int max = Math.max(p[i - 1], Math.max(p[i], p[i + 1]));
        int min = Math.min(p[i - 1], Math.min(p[i], p[i + 1]));

        if (p[i] < max && p[i] > min) {
          ++count;
        }
      }

      System.out.println(count);
    }
  }
} Main public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int n = in.nextInt();
      int[] p = new int[n];

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

      int count = 0;
      for (int i = 1; i < p.length - 1; ++i) {
        int max = Math.max(p[i - 1], Math.max(p[i], p[i + 1]));
        int min = Math.min(p[i - 1], Math.min(p[i], p[i + 1]));

        if (p[i] < max && p[i] > min) {
          ++count;
        }
      }

      System.out.println(count);
    }
  } main {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int n = in.nextInt();
      int[] p = new int[n];

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

      int count = 0;
      for (int i = 1; i < p.length - 1; ++i) {
        int max = Math.max(p[i - 1], Math.max(p[i], p[i + 1]));
        int min = Math.min(p[i - 1], Math.min(p[i], p[i + 1]));

        if (p[i] < max && p[i] > min) {
          ++count;
        }
      }

      System.out.println(count);
    }
  } Scanner in = new Scanner(System.in); in new Scanner(System.in) while (in.hasNext()) {
      int n = in.nextInt();
      int[] p = new int[n];

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

      int count = 0;
      for (int i = 1; i < p.length - 1; ++i) {
        int max = Math.max(p[i - 1], Math.max(p[i], p[i + 1]));
        int min = Math.min(p[i - 1], Math.min(p[i], p[i + 1]));

        if (p[i] < max && p[i] > min) {
          ++count;
        }
      }

      System.out.println(count);
    } in.hasNext() in.hasNext in {
      int n = in.nextInt();
      int[] p = new int[n];

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

      int count = 0;
      for (int i = 1; i < p.length - 1; ++i) {
        int max = Math.max(p[i - 1], Math.max(p[i], p[i + 1]));
        int min = Math.min(p[i - 1], Math.min(p[i], p[i + 1]));

        if (p[i] < max && p[i] > min) {
          ++count;
        }
      }

      System.out.println(count);
    } int n = in.nextInt(); n in.nextInt() in.nextInt in int[] p = new int[n]; p new int[n] n for (int i = 0; i < p.length; ++i) {
        p[i] = in.nextInt();
      } int i = 0; int i = 0; i 0 i < p.length i p.length p p.length ++i ++i i {
        p[i] = in.nextInt();
      } {
        p[i] = in.nextInt();
      } p[i] = in.nextInt() p[i] p i in.nextInt() in.nextInt in int count = 0; count 0 for (int i = 1; i < p.length - 1; ++i) {
        int max = Math.max(p[i - 1], Math.max(p[i], p[i + 1]));
        int min = Math.min(p[i - 1], Math.min(p[i], p[i + 1]));

        if (p[i] < max && p[i] > min) {
          ++count;
        }
      } int i = 1; int i = 1; i 1 i < p.length - 1 i p.length - 1 p.length p p.length 1 ++i ++i i {
        int max = Math.max(p[i - 1], Math.max(p[i], p[i + 1]));
        int min = Math.min(p[i - 1], Math.min(p[i], p[i + 1]));

        if (p[i] < max && p[i] > min) {
          ++count;
        }
      } {
        int max = Math.max(p[i - 1], Math.max(p[i], p[i + 1]));
        int min = Math.min(p[i - 1], Math.min(p[i], p[i + 1]));

        if (p[i] < max && p[i] > min) {
          ++count;
        }
      } int max = Math.max(p[i - 1], Math.max(p[i], p[i + 1])); max Math.max(p[i - 1], Math.max(p[i], p[i + 1])) Math.max Math p[i - 1] p i - 1 i 1 Math.max(p[i], p[i + 1]) Math.max Math p[i] p i p[i + 1] p i + 1 i 1 int min = Math.min(p[i - 1], Math.min(p[i], p[i + 1])); min Math.min(p[i - 1], Math.min(p[i], p[i + 1])) Math.min Math p[i - 1] p i - 1 i 1 Math.min(p[i], p[i + 1]) Math.min Math p[i] p i p[i + 1] p i + 1 i 1 if (p[i] < max && p[i] > min) {
          ++count;
        } p[i] < max && p[i] > min p[i] < max p[i] p i max p[i] > min p[i] p i min {
          ++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 in = new Scanner(System.in);

    while (in.hasNext()) {
      int n = in.nextInt();
      int[] p = new int[n];

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

      int count = 0;
      for (int i = 1; i < p.length - 1; ++i) {
        int max = Math.max(p[i - 1], Math.max(p[i], p[i + 1]));
        int min = Math.min(p[i - 1], Math.min(p[i], p[i + 1]));

        if (p[i] < max && p[i] > min) {
          ++count;
        }
      }

      System.out.println(count);
    }
  }
} public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int n = in.nextInt();
      int[] p = new int[n];

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

      int count = 0;
      for (int i = 1; i < p.length - 1; ++i) {
        int max = Math.max(p[i - 1], Math.max(p[i], p[i + 1]));
        int min = Math.min(p[i - 1], Math.min(p[i], p[i + 1]));

        if (p[i] < max && p[i] > min) {
          ++count;
        }
      }

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

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int n = in.nextInt();
      int[] p = new int[n];

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

      int count = 0;
      for (int i = 1; i < p.length - 1; ++i) {
        int max = Math.max(p[i - 1], Math.max(p[i], p[i + 1]));
        int min = Math.min(p[i - 1], Math.min(p[i], p[i + 1]));

        if (p[i] < max && p[i] > min) {
          ++count;
        }
      }

      System.out.println(count);
    }
  }
}