import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] str = in.readLine().split(" ");
    int count = 0;
    int[] p = new int[n];
    for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
    }
    
    for(int i=1; i<n-1; i++) {
      if(p[i-1]<p[i] && p[i]<p[i+1] || p[i-1]>p[i] && p[i]>p[i+1])
        count+=1;
    }
    System.out.println(count);
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] str = in.readLine().split(" ");
    int count = 0;
    int[] p = new int[n];
    for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
    }
    
    for(int i=1; i<n-1; i++) {
      if(p[i-1]<p[i] && p[i]<p[i+1] || p[i-1]>p[i] && p[i]>p[i+1])
        count+=1;
    }
    System.out.println(count);
  }
} Main public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] str = in.readLine().split(" ");
    int count = 0;
    int[] p = new int[n];
    for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
    }
    
    for(int i=1; i<n-1; i++) {
      if(p[i-1]<p[i] && p[i]<p[i+1] || p[i-1]>p[i] && p[i]>p[i+1])
        count+=1;
    }
    System.out.println(count);
  } main {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] str = in.readLine().split(" ");
    int count = 0;
    int[] p = new int[n];
    for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
    }
    
    for(int i=1; i<n-1; i++) {
      if(p[i-1]<p[i] && p[i]<p[i+1] || p[i-1]>p[i] && p[i]>p[i+1])
        count+=1;
    }
    System.out.println(count);
  } BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(in.readLine()); n Integer.parseInt(in.readLine()) Integer.parseInt Integer in.readLine() in.readLine in String[] str = in.readLine().split(" "); str in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " int count = 0; count 0 int[] p = new int[n]; p new int[n] n for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      p[i] = Integer.parseInt(str[i]);
    } {
      p[i] = Integer.parseInt(str[i]);
    } p[i] = Integer.parseInt(str[i]) p[i] p i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i for(int i=1; i<n-1; i++) {
      if(p[i-1]<p[i] && p[i]<p[i+1] || p[i-1]>p[i] && p[i]>p[i+1])
        count+=1;
    } int i=1; int i=1; i 1 i<n-1 i n-1 n 1 i++ i++ i {
      if(p[i-1]<p[i] && p[i]<p[i+1] || p[i-1]>p[i] && p[i]>p[i+1])
        count+=1;
    } {
      if(p[i-1]<p[i] && p[i]<p[i+1] || p[i-1]>p[i] && p[i]>p[i+1])
        count+=1;
    } if(p[i-1]<p[i] && p[i]<p[i+1] || p[i-1]>p[i] && p[i]>p[i+1])
        count+=1; p[i-1]<p[i] && p[i]<p[i+1] || p[i-1]>p[i] && p[i]>p[i+1] p[i-1]<p[i] && p[i]<p[i+1] p[i-1]<p[i] p[i-1] p i-1 i 1 p[i] p i p[i]<p[i+1] p[i] p i p[i+1] p i+1 i 1 p[i-1]>p[i] && p[i]>p[i+1] p[i-1]>p[i] p[i-1] p i-1 i 1 p[i] p i p[i]>p[i+1] p[i] p i p[i+1] p i+1 i 1 count+=1 count 1 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) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] str = in.readLine().split(" ");
    int count = 0;
    int[] p = new int[n];
    for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
    }
    
    for(int i=1; i<n-1; i++) {
      if(p[i-1]<p[i] && p[i]<p[i+1] || p[i-1]>p[i] && p[i]>p[i+1])
        count+=1;
    }
    System.out.println(count);
  }
} public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] str = in.readLine().split(" ");
    int count = 0;
    int[] p = new int[n];
    for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
    }
    
    for(int i=1; i<n-1; i++) {
      if(p[i-1]<p[i] && p[i]<p[i+1] || p[i-1]>p[i] && p[i]>p[i+1])
        count+=1;
    }
    System.out.println(count);
  }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] str = in.readLine().split(" ");
    int count = 0;
    int[] p = new int[n];
    for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
    }
    
    for(int i=1; i<n-1; i++) {
      if(p[i-1]<p[i] && p[i]<p[i+1] || p[i-1]>p[i] && p[i]>p[i+1])
        count+=1;
    }
    System.out.println(count);
  }
}