import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int N = scan.nextInt();
		 int p[] = new int[N];
		 
		 for (int i = 0; i < N; i++ ) {
			 p[i] = scan.nextInt();
		 }
		 
		 
		 int p_1;
		 int p_2;
		 int p_3;
		 int cnt = 0;
		 
		 for (int i = 0; i < N - 2; i++) {
			 p_1 = p[i];
			 p_2 = p[i + 1];
			 p_3 = p[i + 2];
			 
			 if (p_1 < p_2 && p_2 < p_3) {
				cnt++; 
			 } else if (p_3 < p_2 && p_2 < p_1) {
				cnt++;
			 }
		 }
		 
		 System.out.println(cnt);
		 
		 scan.close();

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int N = scan.nextInt();
		 int p[] = new int[N];
		 
		 for (int i = 0; i < N; i++ ) {
			 p[i] = scan.nextInt();
		 }
		 
		 
		 int p_1;
		 int p_2;
		 int p_3;
		 int cnt = 0;
		 
		 for (int i = 0; i < N - 2; i++) {
			 p_1 = p[i];
			 p_2 = p[i + 1];
			 p_3 = p[i + 2];
			 
			 if (p_1 < p_2 && p_2 < p_3) {
				cnt++; 
			 } else if (p_3 < p_2 && p_2 < p_1) {
				cnt++;
			 }
		 }
		 
		 System.out.println(cnt);
		 
		 scan.close();

	}

} Main public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int N = scan.nextInt();
		 int p[] = new int[N];
		 
		 for (int i = 0; i < N; i++ ) {
			 p[i] = scan.nextInt();
		 }
		 
		 
		 int p_1;
		 int p_2;
		 int p_3;
		 int cnt = 0;
		 
		 for (int i = 0; i < N - 2; i++) {
			 p_1 = p[i];
			 p_2 = p[i + 1];
			 p_3 = p[i + 2];
			 
			 if (p_1 < p_2 && p_2 < p_3) {
				cnt++; 
			 } else if (p_3 < p_2 && p_2 < p_1) {
				cnt++;
			 }
		 }
		 
		 System.out.println(cnt);
		 
		 scan.close();

	} main {
		 Scanner scan = new Scanner(System.in);
		 int N = scan.nextInt();
		 int p[] = new int[N];
		 
		 for (int i = 0; i < N; i++ ) {
			 p[i] = scan.nextInt();
		 }
		 
		 
		 int p_1;
		 int p_2;
		 int p_3;
		 int cnt = 0;
		 
		 for (int i = 0; i < N - 2; i++) {
			 p_1 = p[i];
			 p_2 = p[i + 1];
			 p_3 = p[i + 2];
			 
			 if (p_1 < p_2 && p_2 < p_3) {
				cnt++; 
			 } else if (p_3 < p_2 && p_2 < p_1) {
				cnt++;
			 }
		 }
		 
		 System.out.println(cnt);
		 
		 scan.close();

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int p[] = new int[N]; p new int[N] N for (int i = 0; i < N; i++ ) {
			 p[i] = scan.nextInt();
		 } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			 p[i] = scan.nextInt();
		 } {
			 p[i] = scan.nextInt();
		 } p[i] = scan.nextInt() p[i] p i scan.nextInt() scan.nextInt scan int p_1; p_1 int p_2; p_2 int p_3; p_3 int cnt = 0; cnt 0 for (int i = 0; i < N - 2; i++) {
			 p_1 = p[i];
			 p_2 = p[i + 1];
			 p_3 = p[i + 2];
			 
			 if (p_1 < p_2 && p_2 < p_3) {
				cnt++; 
			 } else if (p_3 < p_2 && p_2 < p_1) {
				cnt++;
			 }
		 } int i = 0; int i = 0; i 0 i < N - 2 i N - 2 N 2 i++ i++ i {
			 p_1 = p[i];
			 p_2 = p[i + 1];
			 p_3 = p[i + 2];
			 
			 if (p_1 < p_2 && p_2 < p_3) {
				cnt++; 
			 } else if (p_3 < p_2 && p_2 < p_1) {
				cnt++;
			 }
		 } {
			 p_1 = p[i];
			 p_2 = p[i + 1];
			 p_3 = p[i + 2];
			 
			 if (p_1 < p_2 && p_2 < p_3) {
				cnt++; 
			 } else if (p_3 < p_2 && p_2 < p_1) {
				cnt++;
			 }
		 } p_1 = p[i] p_1 p[i] p i p_2 = p[i + 1] p_2 p[i + 1] p i + 1 i 1 p_3 = p[i + 2] p_3 p[i + 2] p i + 2 i 2 if (p_1 < p_2 && p_2 < p_3) {
				cnt++; 
			 } else if (p_3 < p_2 && p_2 < p_1) {
				cnt++;
			 } p_1 < p_2 && p_2 < p_3 p_1 < p_2 p_1 p_2 p_2 < p_3 p_2 p_3 {
				cnt++; 
			 } cnt++ cnt if (p_3 < p_2 && p_2 < p_1) {
				cnt++;
			 } p_3 < p_2 && p_2 < p_1 p_3 < p_2 p_3 p_2 p_2 < p_1 p_2 p_1 {
				cnt++;
			 } cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt scan.close() scan.close scan String[] args args public class Main {

	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int N = scan.nextInt();
		 int p[] = new int[N];
		 
		 for (int i = 0; i < N; i++ ) {
			 p[i] = scan.nextInt();
		 }
		 
		 
		 int p_1;
		 int p_2;
		 int p_3;
		 int cnt = 0;
		 
		 for (int i = 0; i < N - 2; i++) {
			 p_1 = p[i];
			 p_2 = p[i + 1];
			 p_3 = p[i + 2];
			 
			 if (p_1 < p_2 && p_2 < p_3) {
				cnt++; 
			 } else if (p_3 < p_2 && p_2 < p_1) {
				cnt++;
			 }
		 }
		 
		 System.out.println(cnt);
		 
		 scan.close();

	}

} public class Main {

	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int N = scan.nextInt();
		 int p[] = new int[N];
		 
		 for (int i = 0; i < N; i++ ) {
			 p[i] = scan.nextInt();
		 }
		 
		 
		 int p_1;
		 int p_2;
		 int p_3;
		 int cnt = 0;
		 
		 for (int i = 0; i < N - 2; i++) {
			 p_1 = p[i];
			 p_2 = p[i + 1];
			 p_3 = p[i + 2];
			 
			 if (p_1 < p_2 && p_2 < p_3) {
				cnt++; 
			 } else if (p_3 < p_2 && p_2 < p_1) {
				cnt++;
			 }
		 }
		 
		 System.out.println(cnt);
		 
		 scan.close();

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int N = scan.nextInt();
		 int p[] = new int[N];
		 
		 for (int i = 0; i < N; i++ ) {
			 p[i] = scan.nextInt();
		 }
		 
		 
		 int p_1;
		 int p_2;
		 int p_3;
		 int cnt = 0;
		 
		 for (int i = 0; i < N - 2; i++) {
			 p_1 = p[i];
			 p_2 = p[i + 1];
			 p_3 = p[i + 2];
			 
			 if (p_1 < p_2 && p_2 < p_3) {
				cnt++; 
			 } else if (p_3 < p_2 && p_2 < p_1) {
				cnt++;
			 }
		 }
		 
		 System.out.println(cnt);
		 
		 scan.close();

	}

}
