import java.util.Scanner;

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 count = 0;
		for(int i=1;i<n-1;i++){
			int tmp[] = new int[3];
			tmp[0] = p[i-1];
			tmp[1] = p[i];
			tmp[2] = p[i+1];
			for(int j=0;j<tmp.length-1;j++){
				for(int k=1;k<tmp.length;k++){
					if(tmp[k-1]>tmp[k]){
						int t = tmp[k-1];
						tmp[k-1] = tmp[k];
						tmp[k] = t;
					}
				}

			}

			if(tmp[1]==p[i]){
				count++;
			}

		}
		System.out.println(count);

	}
} import java.util.Scanner; Scanner java.util 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 count = 0;
		for(int i=1;i<n-1;i++){
			int tmp[] = new int[3];
			tmp[0] = p[i-1];
			tmp[1] = p[i];
			tmp[2] = p[i+1];
			for(int j=0;j<tmp.length-1;j++){
				for(int k=1;k<tmp.length;k++){
					if(tmp[k-1]>tmp[k]){
						int t = tmp[k-1];
						tmp[k-1] = tmp[k];
						tmp[k] = t;
					}
				}

			}

			if(tmp[1]==p[i]){
				count++;
			}

		}
		System.out.println(count);

	}
} 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 count = 0;
		for(int i=1;i<n-1;i++){
			int tmp[] = new int[3];
			tmp[0] = p[i-1];
			tmp[1] = p[i];
			tmp[2] = p[i+1];
			for(int j=0;j<tmp.length-1;j++){
				for(int k=1;k<tmp.length;k++){
					if(tmp[k-1]>tmp[k]){
						int t = tmp[k-1];
						tmp[k-1] = tmp[k];
						tmp[k] = t;
					}
				}

			}

			if(tmp[1]==p[i]){
				count++;
			}

		}
		System.out.println(count);

	} 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 count = 0;
		for(int i=1;i<n-1;i++){
			int tmp[] = new int[3];
			tmp[0] = p[i-1];
			tmp[1] = p[i];
			tmp[2] = p[i+1];
			for(int j=0;j<tmp.length-1;j++){
				for(int k=1;k<tmp.length;k++){
					if(tmp[k-1]>tmp[k]){
						int t = tmp[k-1];
						tmp[k-1] = tmp[k];
						tmp[k] = t;
					}
				}

			}

			if(tmp[1]==p[i]){
				count++;
			}

		}
		System.out.println(count);

	} 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 count = 0; count 0 for(int i=1;i<n-1;i++){
			int tmp[] = new int[3];
			tmp[0] = p[i-1];
			tmp[1] = p[i];
			tmp[2] = p[i+1];
			for(int j=0;j<tmp.length-1;j++){
				for(int k=1;k<tmp.length;k++){
					if(tmp[k-1]>tmp[k]){
						int t = tmp[k-1];
						tmp[k-1] = tmp[k];
						tmp[k] = t;
					}
				}

			}

			if(tmp[1]==p[i]){
				count++;
			}

		} int i=1; int i=1; i 1 i<n-1 i n-1 n 1 i++ i++ i {
			int tmp[] = new int[3];
			tmp[0] = p[i-1];
			tmp[1] = p[i];
			tmp[2] = p[i+1];
			for(int j=0;j<tmp.length-1;j++){
				for(int k=1;k<tmp.length;k++){
					if(tmp[k-1]>tmp[k]){
						int t = tmp[k-1];
						tmp[k-1] = tmp[k];
						tmp[k] = t;
					}
				}

			}

			if(tmp[1]==p[i]){
				count++;
			}

		} {
			int tmp[] = new int[3];
			tmp[0] = p[i-1];
			tmp[1] = p[i];
			tmp[2] = p[i+1];
			for(int j=0;j<tmp.length-1;j++){
				for(int k=1;k<tmp.length;k++){
					if(tmp[k-1]>tmp[k]){
						int t = tmp[k-1];
						tmp[k-1] = tmp[k];
						tmp[k] = t;
					}
				}

			}

			if(tmp[1]==p[i]){
				count++;
			}

		} int tmp[] = new int[3]; tmp new int[3] 3 tmp[0] = p[i-1] tmp[0] tmp 0 p[i-1] p i-1 i 1 tmp[1] = p[i] tmp[1] tmp 1 p[i] p i tmp[2] = p[i+1] tmp[2] tmp 2 p[i+1] p i+1 i 1 for(int j=0;j<tmp.length-1;j++){
				for(int k=1;k<tmp.length;k++){
					if(tmp[k-1]>tmp[k]){
						int t = tmp[k-1];
						tmp[k-1] = tmp[k];
						tmp[k] = t;
					}
				}

			} int j=0; int j=0; j 0 j<tmp.length-1 j tmp.length-1 tmp.length tmp tmp.length 1 j++ j++ j {
				for(int k=1;k<tmp.length;k++){
					if(tmp[k-1]>tmp[k]){
						int t = tmp[k-1];
						tmp[k-1] = tmp[k];
						tmp[k] = t;
					}
				}

			} {
				for(int k=1;k<tmp.length;k++){
					if(tmp[k-1]>tmp[k]){
						int t = tmp[k-1];
						tmp[k-1] = tmp[k];
						tmp[k] = t;
					}
				}

			} for(int k=1;k<tmp.length;k++){
					if(tmp[k-1]>tmp[k]){
						int t = tmp[k-1];
						tmp[k-1] = tmp[k];
						tmp[k] = t;
					}
				} int k=1; int k=1; k 1 k<tmp.length k tmp.length tmp tmp.length k++ k++ k {
					if(tmp[k-1]>tmp[k]){
						int t = tmp[k-1];
						tmp[k-1] = tmp[k];
						tmp[k] = t;
					}
				} {
					if(tmp[k-1]>tmp[k]){
						int t = tmp[k-1];
						tmp[k-1] = tmp[k];
						tmp[k] = t;
					}
				} if(tmp[k-1]>tmp[k]){
						int t = tmp[k-1];
						tmp[k-1] = tmp[k];
						tmp[k] = t;
					} tmp[k-1]>tmp[k] tmp[k-1] tmp k-1 k 1 tmp[k] tmp k {
						int t = tmp[k-1];
						tmp[k-1] = tmp[k];
						tmp[k] = t;
					} int t = tmp[k-1]; t tmp[k-1] tmp k-1 k 1 tmp[k-1] = tmp[k] tmp[k-1] tmp k-1 k 1 tmp[k] tmp k tmp[k] = t tmp[k] tmp k t if(tmp[1]==p[i]){
				count++;
			} tmp[1]==p[i] tmp[1] tmp 1 p[i] p i {
				count++;
			} count++ count System.out.println(count) System.out.println System.out System System.out count String args[] args
import java.util.Scanner;

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 count = 0;
		for(int i=1;i<n-1;i++){
			int tmp[] = new int[3];
			tmp[0] = p[i-1];
			tmp[1] = p[i];
			tmp[2] = p[i+1];
			for(int j=0;j<tmp.length-1;j++){
				for(int k=1;k<tmp.length;k++){
					if(tmp[k-1]>tmp[k]){
						int t = tmp[k-1];
						tmp[k-1] = tmp[k];
						tmp[k] = t;
					}
				}

			}

			if(tmp[1]==p[i]){
				count++;
			}

		}
		System.out.println(count);

	}
}
