import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int[] setArray(int a[]) {
		for(int i=0;i<a.length;i++) {
			a[i]=scan.nextInt();
		}
		return a;
	}
		public static void main(String[] args) {
			int a=scan.nextInt();
			int b[]=new int[a];
			b=setArray(b);
			int cnt=0;
			for(int i=1;i<a-1;i++) {
				if(b[i]>b[i-1]&&b[i]<b[i+1]||b[i]<b[i-1]&&b[i]>b[i+1]) {
					cnt++;
				}
			}
			System.out.println(cnt);
		}
} import java.util.Scanner; Scanner java.util public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int[] setArray(int a[]) {
		for(int i=0;i<a.length;i++) {
			a[i]=scan.nextInt();
		}
		return a;
	}
		public static void main(String[] args) {
			int a=scan.nextInt();
			int b[]=new int[a];
			b=setArray(b);
			int cnt=0;
			for(int i=1;i<a-1;i++) {
				if(b[i]>b[i-1]&&b[i]<b[i+1]||b[i]<b[i-1]&&b[i]>b[i+1]) {
					cnt++;
				}
			}
			System.out.println(cnt);
		}
} Main static Scanner scan=new Scanner(System.in); scan new Scanner(System.in) static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;} gcd {return b>0?gcd(b,a%b):a;} return b>0?gcd(b,a%b):a; b>0?gcd(b,a%b):a b>0 b 0 gcd(b,a%b) gcd b a%b a b a int a a int b b static long lcm (int a, int b) {return a*b/gcd(a,b);} lcm {return a*b/gcd(a,b);} return a*b/gcd(a,b); a*b/gcd(a,b) a*b a b gcd(a,b) gcd a b int a a int b b static int max(int a,int b) {return a>b?a:b;} max {return a>b?a:b;} return a>b?a:b; a>b?a:b a>b a b a b int a a int b b static int min(int a,int b) {return a<b?a:b;} min {return a<b?a:b;} return a<b?a:b; a<b?a:b a<b a b a b int a a int b b static long factorial(int i) {return i==1?1:i*factorial(i-1);} factorial {return i==1?1:i*factorial(i-1);} return i==1?1:i*factorial(i-1); i==1?1:i*factorial(i-1) i==1 i 1 1 i*factorial(i-1) i factorial(i-1) factorial i-1 i 1 int i i static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		} lower_bound {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		} int low=0 low 0 high=a.length; high a.length a a.length while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		} low<high low high {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		} int mid=((high-low)/2)+low; mid ((high-low)/2)+low ((high-low)/2) (high-low) high low 2 low if(a[mid]<=key)low=mid+1;
			else high=mid; a[mid]<=key a[mid] a mid key low=mid+1 low mid+1 mid 1 high=mid high mid return high; high int a[] a int key key static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		} upper_bound {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		} int low=0 low 0 high=a.length; high a.length a a.length while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		} low<high low high {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		} int mid=((high-low)/2)+low; mid ((high-low)/2)+low ((high-low)/2) (high-low) high low 2 low if(a[mid]<key)low=mid+1;
			else high=mid; a[mid]<key a[mid] a mid key low=mid+1 low mid+1 mid 1 high=mid high mid return high; high int a[] a int key key static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	} isPrime {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	} if (n==2) return true; n==2 n 2 return true; true if (n<2 || n%2==0) return false; n<2 || n%2==0 n<2 n 2 n%2==0 n%2 n 2 0 return false; false double d = Math.sqrt(n); d Math.sqrt(n) Math.sqrt Math n for (int i=3; i<=d; i+=2)if(n%i==0){return false;} int i=3; int i=3; i 3 i<=d i d i+=2 i+=2 i 2 if(n%i==0){return false;} if(n%i==0){return false;} n%i==0 n%i n i 0 {return false;} return false; false return true; true int n n static int[] setArray(int a[]) {
		for(int i=0;i<a.length;i++) {
			a[i]=scan.nextInt();
		}
		return a;
	} setArray {
		for(int i=0;i<a.length;i++) {
			a[i]=scan.nextInt();
		}
		return a;
	} for(int i=0;i<a.length;i++) {
			a[i]=scan.nextInt();
		} int i=0; int i=0; i 0 i<a.length i a.length a a.length i++ i++ i {
			a[i]=scan.nextInt();
		} {
			a[i]=scan.nextInt();
		} a[i]=scan.nextInt() a[i] a i scan.nextInt() scan.nextInt scan return a; a int a[] a public static void main(String[] args) {
			int a=scan.nextInt();
			int b[]=new int[a];
			b=setArray(b);
			int cnt=0;
			for(int i=1;i<a-1;i++) {
				if(b[i]>b[i-1]&&b[i]<b[i+1]||b[i]<b[i-1]&&b[i]>b[i+1]) {
					cnt++;
				}
			}
			System.out.println(cnt);
		} main {
			int a=scan.nextInt();
			int b[]=new int[a];
			b=setArray(b);
			int cnt=0;
			for(int i=1;i<a-1;i++) {
				if(b[i]>b[i-1]&&b[i]<b[i+1]||b[i]<b[i-1]&&b[i]>b[i+1]) {
					cnt++;
				}
			}
			System.out.println(cnt);
		} int a=scan.nextInt(); a scan.nextInt() scan.nextInt scan int b[]=new int[a]; b new int[a] a b=setArray(b) b setArray(b) setArray b int cnt=0; cnt 0 for(int i=1;i<a-1;i++) {
				if(b[i]>b[i-1]&&b[i]<b[i+1]||b[i]<b[i-1]&&b[i]>b[i+1]) {
					cnt++;
				}
			} int i=1; int i=1; i 1 i<a-1 i a-1 a 1 i++ i++ i {
				if(b[i]>b[i-1]&&b[i]<b[i+1]||b[i]<b[i-1]&&b[i]>b[i+1]) {
					cnt++;
				}
			} {
				if(b[i]>b[i-1]&&b[i]<b[i+1]||b[i]<b[i-1]&&b[i]>b[i+1]) {
					cnt++;
				}
			} if(b[i]>b[i-1]&&b[i]<b[i+1]||b[i]<b[i-1]&&b[i]>b[i+1]) {
					cnt++;
				} b[i]>b[i-1]&&b[i]<b[i+1]||b[i]<b[i-1]&&b[i]>b[i+1] b[i]>b[i-1]&&b[i]<b[i+1] b[i]>b[i-1] b[i] b i b[i-1] b i-1 i 1 b[i]<b[i+1] b[i] b i b[i+1] b i+1 i 1 b[i]<b[i-1]&&b[i]>b[i+1] b[i]<b[i-1] b[i] b i b[i-1] b i-1 i 1 b[i]>b[i+1] b[i] b i b[i+1] b i+1 i 1 {
					cnt++;
				} cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int[] setArray(int a[]) {
		for(int i=0;i<a.length;i++) {
			a[i]=scan.nextInt();
		}
		return a;
	}
		public static void main(String[] args) {
			int a=scan.nextInt();
			int b[]=new int[a];
			b=setArray(b);
			int cnt=0;
			for(int i=1;i<a-1;i++) {
				if(b[i]>b[i-1]&&b[i]<b[i+1]||b[i]<b[i-1]&&b[i]>b[i+1]) {
					cnt++;
				}
			}
			System.out.println(cnt);
		}
} public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int[] setArray(int a[]) {
		for(int i=0;i<a.length;i++) {
			a[i]=scan.nextInt();
		}
		return a;
	}
		public static void main(String[] args) {
			int a=scan.nextInt();
			int b[]=new int[a];
			b=setArray(b);
			int cnt=0;
			for(int i=1;i<a-1;i++) {
				if(b[i]>b[i-1]&&b[i]<b[i+1]||b[i]<b[i-1]&&b[i]>b[i+1]) {
					cnt++;
				}
			}
			System.out.println(cnt);
		}
} Main
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int[] setArray(int a[]) {
		for(int i=0;i<a.length;i++) {
			a[i]=scan.nextInt();
		}
		return a;
	}
		public static void main(String[] args) {
			int a=scan.nextInt();
			int b[]=new int[a];
			b=setArray(b);
			int cnt=0;
			for(int i=1;i<a-1;i++) {
				if(b[i]>b[i-1]&&b[i]<b[i+1]||b[i]<b[i-1]&&b[i]>b[i+1]) {
					cnt++;
				}
			}
			System.out.println(cnt);
		}
}
