
import java.util.*;


public class Main {
	
	
	public static void main(String[] args) {

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

		Scanner s = new Scanner(System.in);
		
		int n = s.nextInt();
		int[] a = new int[n+1];
		for(int i = 1;i<=n;i++)a[i] = s.nextInt();
		int c=  0;
		for(int i = 2;i<n;i++)
		{
			if((a[i]>a[i-1]&&a[i]>a[i+1])||(a[i]<a[i-1]&&a[i]<a[i+1]))
			{}else c++;
		}
		
		 System.out.println(c);
	}
} Main public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		
		int n = s.nextInt();
		int[] a = new int[n+1];
		for(int i = 1;i<=n;i++)a[i] = s.nextInt();
		int c=  0;
		for(int i = 2;i<n;i++)
		{
			if((a[i]>a[i-1]&&a[i]>a[i+1])||(a[i]<a[i-1]&&a[i]<a[i+1]))
			{}else c++;
		}
		
		 System.out.println(c);
	} main {

		Scanner s = new Scanner(System.in);
		
		int n = s.nextInt();
		int[] a = new int[n+1];
		for(int i = 1;i<=n;i++)a[i] = s.nextInt();
		int c=  0;
		for(int i = 2;i<n;i++)
		{
			if((a[i]>a[i-1]&&a[i]>a[i+1])||(a[i]<a[i-1]&&a[i]<a[i+1]))
			{}else c++;
		}
		
		 System.out.println(c);
	} Scanner s = new Scanner(System.in); s new Scanner(System.in) int n = s.nextInt(); n s.nextInt() s.nextInt s int[] a = new int[n+1]; a new int[n+1] n+1 n 1 for(int i = 1;i<=n;i++)a[i] = s.nextInt(); int i = 1; int i = 1; i 1 i<=n i n i++ i++ i a[i] = s.nextInt(); a[i] = s.nextInt() a[i] a i s.nextInt() s.nextInt s int c=  0; c 0 for(int i = 2;i<n;i++)
		{
			if((a[i]>a[i-1]&&a[i]>a[i+1])||(a[i]<a[i-1]&&a[i]<a[i+1]))
			{}else c++;
		} int i = 2; int i = 2; i 2 i<n i n i++ i++ i {
			if((a[i]>a[i-1]&&a[i]>a[i+1])||(a[i]<a[i-1]&&a[i]<a[i+1]))
			{}else c++;
		} {
			if((a[i]>a[i-1]&&a[i]>a[i+1])||(a[i]<a[i-1]&&a[i]<a[i+1]))
			{}else c++;
		} if((a[i]>a[i-1]&&a[i]>a[i+1])||(a[i]<a[i-1]&&a[i]<a[i+1]))
			{}else c++; (a[i]>a[i-1]&&a[i]>a[i+1])||(a[i]<a[i-1]&&a[i]<a[i+1]) (a[i]>a[i-1]&&a[i]>a[i+1]) a[i]>a[i-1] a[i] a i a[i-1] a i-1 i 1 a[i]>a[i+1] a[i] a i a[i+1] a i+1 i 1 (a[i]<a[i-1]&&a[i]<a[i+1]) a[i]<a[i-1] a[i] a i a[i-1] a i-1 i 1 a[i]<a[i+1] a[i] a i a[i+1] a i+1 i 1 {} c++ c System.out.println(c) System.out.println System.out System System.out c String[] args args public class Main {
	
	
	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		
		int n = s.nextInt();
		int[] a = new int[n+1];
		for(int i = 1;i<=n;i++)a[i] = s.nextInt();
		int c=  0;
		for(int i = 2;i<n;i++)
		{
			if((a[i]>a[i-1]&&a[i]>a[i+1])||(a[i]<a[i-1]&&a[i]<a[i+1]))
			{}else c++;
		}
		
		 System.out.println(c);
	}
} public class Main {
	
	
	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		
		int n = s.nextInt();
		int[] a = new int[n+1];
		for(int i = 1;i<=n;i++)a[i] = s.nextInt();
		int c=  0;
		for(int i = 2;i<n;i++)
		{
			if((a[i]>a[i-1]&&a[i]>a[i+1])||(a[i]<a[i-1]&&a[i]<a[i+1]))
			{}else c++;
		}
		
		 System.out.println(c);
	}
} Main

import java.util.*;


public class Main {
	
	
	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		
		int n = s.nextInt();
		int[] a = new int[n+1];
		for(int i = 1;i<=n;i++)a[i] = s.nextInt();
		int c=  0;
		for(int i = 2;i<n;i++)
		{
			if((a[i]>a[i-1]&&a[i]>a[i+1])||(a[i]<a[i-1]&&a[i]<a[i+1]))
			{}else c++;
		}
		
		 System.out.println(c);
	}
}
