import java.util.*;
import java.math.*;
class Main{
public static void main(String[] args) {
  Scanner stdIn = new Scanner(System.in);
  int n = stdIn.nextInt();
  int[] p = new int[n];
  for(int i = 0;i<p.length;i++) {
    p[i] = stdIn.nextInt();
  }
  int[] unko = new int[3];
  int count = 0;
  for(int i = 0;i<p.length-2;i++) {
    int a = p[i];
    int b = p[i+1];
    int c = p[i+2];
    unko[0] = a;
    unko[1] = b;
    unko[2] = c;
    Arrays.sort(unko);
    if(unko[1]==b) {
      count += 1;
    }
  }
  System.out.println(count);
}
} import java.util.*; util.* java import java.math.*; math.* java class Main{
public static void main(String[] args) {
  Scanner stdIn = new Scanner(System.in);
  int n = stdIn.nextInt();
  int[] p = new int[n];
  for(int i = 0;i<p.length;i++) {
    p[i] = stdIn.nextInt();
  }
  int[] unko = new int[3];
  int count = 0;
  for(int i = 0;i<p.length-2;i++) {
    int a = p[i];
    int b = p[i+1];
    int c = p[i+2];
    unko[0] = a;
    unko[1] = b;
    unko[2] = c;
    Arrays.sort(unko);
    if(unko[1]==b) {
      count += 1;
    }
  }
  System.out.println(count);
}
} Main public static void main(String[] args) {
  Scanner stdIn = new Scanner(System.in);
  int n = stdIn.nextInt();
  int[] p = new int[n];
  for(int i = 0;i<p.length;i++) {
    p[i] = stdIn.nextInt();
  }
  int[] unko = new int[3];
  int count = 0;
  for(int i = 0;i<p.length-2;i++) {
    int a = p[i];
    int b = p[i+1];
    int c = p[i+2];
    unko[0] = a;
    unko[1] = b;
    unko[2] = c;
    Arrays.sort(unko);
    if(unko[1]==b) {
      count += 1;
    }
  }
  System.out.println(count);
} main {
  Scanner stdIn = new Scanner(System.in);
  int n = stdIn.nextInt();
  int[] p = new int[n];
  for(int i = 0;i<p.length;i++) {
    p[i] = stdIn.nextInt();
  }
  int[] unko = new int[3];
  int count = 0;
  for(int i = 0;i<p.length-2;i++) {
    int a = p[i];
    int b = p[i+1];
    int c = p[i+2];
    unko[0] = a;
    unko[1] = b;
    unko[2] = c;
    Arrays.sort(unko);
    if(unko[1]==b) {
      count += 1;
    }
  }
  System.out.println(count);
} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int[] p = new int[n]; p new int[n] n for(int i = 0;i<p.length;i++) {
    p[i] = stdIn.nextInt();
  } int i = 0; int i = 0; i 0 i<p.length i p.length p p.length i++ i++ i {
    p[i] = stdIn.nextInt();
  } {
    p[i] = stdIn.nextInt();
  } p[i] = stdIn.nextInt() p[i] p i stdIn.nextInt() stdIn.nextInt stdIn int[] unko = new int[3]; unko new int[3] 3 int count = 0; count 0 for(int i = 0;i<p.length-2;i++) {
    int a = p[i];
    int b = p[i+1];
    int c = p[i+2];
    unko[0] = a;
    unko[1] = b;
    unko[2] = c;
    Arrays.sort(unko);
    if(unko[1]==b) {
      count += 1;
    }
  } int i = 0; int i = 0; i 0 i<p.length-2 i p.length-2 p.length p p.length 2 i++ i++ i {
    int a = p[i];
    int b = p[i+1];
    int c = p[i+2];
    unko[0] = a;
    unko[1] = b;
    unko[2] = c;
    Arrays.sort(unko);
    if(unko[1]==b) {
      count += 1;
    }
  } {
    int a = p[i];
    int b = p[i+1];
    int c = p[i+2];
    unko[0] = a;
    unko[1] = b;
    unko[2] = c;
    Arrays.sort(unko);
    if(unko[1]==b) {
      count += 1;
    }
  } int a = p[i]; a p[i] p i int b = p[i+1]; b p[i+1] p i+1 i 1 int c = p[i+2]; c p[i+2] p i+2 i 2 unko[0] = a unko[0] unko 0 a unko[1] = b unko[1] unko 1 b unko[2] = c unko[2] unko 2 c Arrays.sort(unko) Arrays.sort Arrays unko if(unko[1]==b) {
      count += 1;
    } unko[1]==b unko[1] unko 1 b {
      count += 1;
    } count += 1 count 1 System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.*;
import java.math.*;
class Main{
public static void main(String[] args) {
  Scanner stdIn = new Scanner(System.in);
  int n = stdIn.nextInt();
  int[] p = new int[n];
  for(int i = 0;i<p.length;i++) {
    p[i] = stdIn.nextInt();
  }
  int[] unko = new int[3];
  int count = 0;
  for(int i = 0;i<p.length-2;i++) {
    int a = p[i];
    int b = p[i+1];
    int c = p[i+2];
    unko[0] = a;
    unko[1] = b;
    unko[2] = c;
    Arrays.sort(unko);
    if(unko[1]==b) {
      count += 1;
    }
  }
  System.out.println(count);
}
}
