import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int l = sc.nextInt();
		int m = sc.nextInt();
		int r = 0;
		int ans = 0;

		for(int i=0;i<n-2;i++){
			r = sc.nextInt();
			if(l<=m&&m<=r||l>=m&&m>=r)ans++;
			l=m;
			m=r;
		}

		// 出力
		System.out.println(ans);
	}
} 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 l = sc.nextInt();
		int m = sc.nextInt();
		int r = 0;
		int ans = 0;

		for(int i=0;i<n-2;i++){
			r = sc.nextInt();
			if(l<=m&&m<=r||l>=m&&m>=r)ans++;
			l=m;
			m=r;
		}

		// 出力
		System.out.println(ans);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int l = sc.nextInt();
		int m = sc.nextInt();
		int r = 0;
		int ans = 0;

		for(int i=0;i<n-2;i++){
			r = sc.nextInt();
			if(l<=m&&m<=r||l>=m&&m>=r)ans++;
			l=m;
			m=r;
		}

		// 出力
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int l = sc.nextInt();
		int m = sc.nextInt();
		int r = 0;
		int ans = 0;

		for(int i=0;i<n-2;i++){
			r = sc.nextInt();
			if(l<=m&&m<=r||l>=m&&m>=r)ans++;
			l=m;
			m=r;
		}

		// 出力
		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 l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int r = 0; r 0 int ans = 0; ans 0 for(int i=0;i<n-2;i++){
			r = sc.nextInt();
			if(l<=m&&m<=r||l>=m&&m>=r)ans++;
			l=m;
			m=r;
		} int i=0; int i=0; i 0 i<n-2 i n-2 n 2 i++ i++ i {
			r = sc.nextInt();
			if(l<=m&&m<=r||l>=m&&m>=r)ans++;
			l=m;
			m=r;
		} {
			r = sc.nextInt();
			if(l<=m&&m<=r||l>=m&&m>=r)ans++;
			l=m;
			m=r;
		} r = sc.nextInt() r sc.nextInt() sc.nextInt sc if(l<=m&&m<=r||l>=m&&m>=r)ans++; l<=m&&m<=r||l>=m&&m>=r l<=m&&m<=r l<=m l m m<=r m r l>=m&&m>=r l>=m l m m>=r m r ans++ ans l=m l m m=r m r 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 l = sc.nextInt();
		int m = sc.nextInt();
		int r = 0;
		int ans = 0;

		for(int i=0;i<n-2;i++){
			r = sc.nextInt();
			if(l<=m&&m<=r||l>=m&&m>=r)ans++;
			l=m;
			m=r;
		}

		// 出力
		System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int l = sc.nextInt();
		int m = sc.nextInt();
		int r = 0;
		int ans = 0;

		for(int i=0;i<n-2;i++){
			r = sc.nextInt();
			if(l<=m&&m<=r||l>=m&&m>=r)ans++;
			l=m;
			m=r;
		}

		// 出力
		System.out.println(ans);
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int l = sc.nextInt();
		int m = sc.nextInt();
		int r = 0;
		int ans = 0;

		for(int i=0;i<n-2;i++){
			r = sc.nextInt();
			if(l<=m&&m<=r||l>=m&&m>=r)ans++;
			l=m;
			m=r;
		}

		// 出力
		System.out.println(ans);
	}
}