import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
	int[] a = new int[n];
	int count = 0, p = 0, q = 0;
	for(int i = 0; i < n; i++){
		a[i] = Integer.parseInt(sc.next());
	}
	for(int i = 0; i < n-2; i++){
		if(a[i] > a[i+1])p++;
		if(a[i+2] > a[i+1])q++;
		if((p+q) == 1)count++;
		p=0;
		q=0;
	}
	System.out.println(count);
}
} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java public class Main{
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
	int[] a = new int[n];
	int count = 0, p = 0, q = 0;
	for(int i = 0; i < n; i++){
		a[i] = Integer.parseInt(sc.next());
	}
	for(int i = 0; i < n-2; i++){
		if(a[i] > a[i+1])p++;
		if(a[i+2] > a[i+1])q++;
		if((p+q) == 1)count++;
		p=0;
		q=0;
	}
	System.out.println(count);
}
} Main public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
	int[] a = new int[n];
	int count = 0, p = 0, q = 0;
	for(int i = 0; i < n; i++){
		a[i] = Integer.parseInt(sc.next());
	}
	for(int i = 0; i < n-2; i++){
		if(a[i] > a[i+1])p++;
		if(a[i+2] > a[i+1])q++;
		if((p+q) == 1)count++;
		p=0;
		q=0;
	}
	System.out.println(count);
} main {
	Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
	int[] a = new int[n];
	int count = 0, p = 0, q = 0;
	for(int i = 0; i < n; i++){
		a[i] = Integer.parseInt(sc.next());
	}
	for(int i = 0; i < n-2; i++){
		if(a[i] > a[i+1])p++;
		if(a[i+2] > a[i+1])q++;
		if((p+q) == 1)count++;
		p=0;
		q=0;
	}
	System.out.println(count);
} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] a = new int[n]; a new int[n] n int count = 0 count 0 p = 0 p 0 q = 0; q 0 for(int i = 0; i < n; i++){
		a[i] = Integer.parseInt(sc.next());
	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
		a[i] = Integer.parseInt(sc.next());
	} {
		a[i] = Integer.parseInt(sc.next());
	} a[i] = Integer.parseInt(sc.next()) a[i] a i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc for(int i = 0; i < n-2; i++){
		if(a[i] > a[i+1])p++;
		if(a[i+2] > a[i+1])q++;
		if((p+q) == 1)count++;
		p=0;
		q=0;
	} int i = 0; int i = 0; i 0 i < n-2 i n-2 n 2 i++ i++ i {
		if(a[i] > a[i+1])p++;
		if(a[i+2] > a[i+1])q++;
		if((p+q) == 1)count++;
		p=0;
		q=0;
	} {
		if(a[i] > a[i+1])p++;
		if(a[i+2] > a[i+1])q++;
		if((p+q) == 1)count++;
		p=0;
		q=0;
	} if(a[i] > a[i+1])p++; a[i] > a[i+1] a[i] a i a[i+1] a i+1 i 1 p++ p if(a[i+2] > a[i+1])q++; a[i+2] > a[i+1] a[i+2] a i+2 i 2 a[i+1] a i+1 i 1 q++ q if((p+q) == 1)count++; (p+q) == 1 (p+q) p q 1 count++ count p=0 p 0 q=0 q 0 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main{
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
	int[] a = new int[n];
	int count = 0, p = 0, q = 0;
	for(int i = 0; i < n; i++){
		a[i] = Integer.parseInt(sc.next());
	}
	for(int i = 0; i < n-2; i++){
		if(a[i] > a[i+1])p++;
		if(a[i+2] > a[i+1])q++;
		if((p+q) == 1)count++;
		p=0;
		q=0;
	}
	System.out.println(count);
}
} public class Main{
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
	int[] a = new int[n];
	int count = 0, p = 0, q = 0;
	for(int i = 0; i < n; i++){
		a[i] = Integer.parseInt(sc.next());
	}
	for(int i = 0; i < n-2; i++){
		if(a[i] > a[i+1])p++;
		if(a[i+2] > a[i+1])q++;
		if((p+q) == 1)count++;
		p=0;
		q=0;
	}
	System.out.println(count);
}
} Main
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
	int[] a = new int[n];
	int count = 0, p = 0, q = 0;
	for(int i = 0; i < n; i++){
		a[i] = Integer.parseInt(sc.next());
	}
	for(int i = 0; i < n-2; i++){
		if(a[i] > a[i+1])p++;
		if(a[i+2] > a[i+1])q++;
		if((p+q) == 1)count++;
		p=0;
		q=0;
	}
	System.out.println(count);
}
}