import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int n=sc.nextInt();
    int N[] =new int[n];
    int x=0;
    for(int i=0;i<n;i++){
      N[i]=sc.nextInt();}
    for(int j=1;j<n-1;j++){
      if((N[j-1]<N[j])&&(N[j]<N[j+1])){x=x+1;}
      else if((N[j-1]>N[j])&&(N[j]>N[j+1])){x=x+1;}}
    System.out.println(x);
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int n=sc.nextInt();
    int N[] =new int[n];
    int x=0;
    for(int i=0;i<n;i++){
      N[i]=sc.nextInt();}
    for(int j=1;j<n-1;j++){
      if((N[j-1]<N[j])&&(N[j]<N[j+1])){x=x+1;}
      else if((N[j-1]>N[j])&&(N[j]>N[j+1])){x=x+1;}}
    System.out.println(x);
  }
} Main public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int n=sc.nextInt();
    int N[] =new int[n];
    int x=0;
    for(int i=0;i<n;i++){
      N[i]=sc.nextInt();}
    for(int j=1;j<n-1;j++){
      if((N[j-1]<N[j])&&(N[j]<N[j+1])){x=x+1;}
      else if((N[j-1]>N[j])&&(N[j]>N[j+1])){x=x+1;}}
    System.out.println(x);
  } main {
    Scanner sc =new Scanner(System.in);
    int n=sc.nextInt();
    int N[] =new int[n];
    int x=0;
    for(int i=0;i<n;i++){
      N[i]=sc.nextInt();}
    for(int j=1;j<n-1;j++){
      if((N[j-1]<N[j])&&(N[j]<N[j+1])){x=x+1;}
      else if((N[j-1]>N[j])&&(N[j]>N[j+1])){x=x+1;}}
    System.out.println(x);
  } Scanner sc =new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int N[] =new int[n]; N new int[n] n int x=0; x 0 for(int i=0;i<n;i++){
      N[i]=sc.nextInt();} int i=0; int i=0; i 0 i<n i n i++ i++ i {
      N[i]=sc.nextInt();} {
      N[i]=sc.nextInt();} N[i]=sc.nextInt() N[i] N i sc.nextInt() sc.nextInt sc for(int j=1;j<n-1;j++){
      if((N[j-1]<N[j])&&(N[j]<N[j+1])){x=x+1;}
      else if((N[j-1]>N[j])&&(N[j]>N[j+1])){x=x+1;}} int j=1; int j=1; j 1 j<n-1 j n-1 n 1 j++ j++ j {
      if((N[j-1]<N[j])&&(N[j]<N[j+1])){x=x+1;}
      else if((N[j-1]>N[j])&&(N[j]>N[j+1])){x=x+1;}} {
      if((N[j-1]<N[j])&&(N[j]<N[j+1])){x=x+1;}
      else if((N[j-1]>N[j])&&(N[j]>N[j+1])){x=x+1;}} if((N[j-1]<N[j])&&(N[j]<N[j+1])){x=x+1;}
      else if((N[j-1]>N[j])&&(N[j]>N[j+1])){x=x+1;} (N[j-1]<N[j])&&(N[j]<N[j+1]) (N[j-1]<N[j]) N[j-1] N j-1 j 1 N[j] N j (N[j]<N[j+1]) N[j] N j N[j+1] N j+1 j 1 {x=x+1;} x=x+1 x x+1 x 1 if((N[j-1]>N[j])&&(N[j]>N[j+1])){x=x+1;} (N[j-1]>N[j])&&(N[j]>N[j+1]) (N[j-1]>N[j]) N[j-1] N j-1 j 1 N[j] N j (N[j]>N[j+1]) N[j] N j N[j+1] N j+1 j 1 {x=x+1;} x=x+1 x x+1 x 1 System.out.println(x) System.out.println System.out System System.out x String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int n=sc.nextInt();
    int N[] =new int[n];
    int x=0;
    for(int i=0;i<n;i++){
      N[i]=sc.nextInt();}
    for(int j=1;j<n-1;j++){
      if((N[j-1]<N[j])&&(N[j]<N[j+1])){x=x+1;}
      else if((N[j-1]>N[j])&&(N[j]>N[j+1])){x=x+1;}}
    System.out.println(x);
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int n=sc.nextInt();
    int N[] =new int[n];
    int x=0;
    for(int i=0;i<n;i++){
      N[i]=sc.nextInt();}
    for(int j=1;j<n-1;j++){
      if((N[j-1]<N[j])&&(N[j]<N[j+1])){x=x+1;}
      else if((N[j-1]>N[j])&&(N[j]>N[j+1])){x=x+1;}}
    System.out.println(x);
  }
} Main
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int n=sc.nextInt();
    int N[] =new int[n];
    int x=0;
    for(int i=0;i<n;i++){
      N[i]=sc.nextInt();}
    for(int j=1;j<n-1;j++){
      if((N[j-1]<N[j])&&(N[j]<N[j+1])){x=x+1;}
      else if((N[j-1]>N[j])&&(N[j]>N[j+1])){x=x+1;}}
    System.out.println(x);
  }
}