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