import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.stream.Stream; public class No00000116_Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] arr = Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); int cnt = 0; for(int i = 1; i < n - 1; i++) { cnt += check(arr[i - 1], arr[i], arr[i + 1]); } System.out.println(cnt); } private static int check(int num1, int num2, int num3) { if(num1 == num2 || num2 == num3 || num3 == num1) { return 0; } if(Math.max(Math.max(num1, num2), num3) == num2 || Math.min(Math.min(num1, num2), num3) == num2) { return 1; } return 0; } }