import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.awt.Point;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] nums = new int[n];
        String[] s = br.readLine().split(" ");
        
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(s[i]);
        }
        
        int count = 0;
        for (int i = 1; i < n-1; i++) {
            if (nums[i-1] < nums[i] && nums[i] < nums[i+1]) count++;
            else if (nums[i-1] > nums[i] && nums[i] > nums[i+1]) count++;
        }
        
        System.out.println(count);
    }
}


 import java.util.*; util.* java import java.io.InputStreamReader; InputStreamReader java.io import java.io.BufferedReader; BufferedReader java.io import java.awt.Point; Point java.awt public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] nums = new int[n];
        String[] s = br.readLine().split(" ");
        
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(s[i]);
        }
        
        int count = 0;
        for (int i = 1; i < n-1; i++) {
            if (nums[i-1] < nums[i] && nums[i] < nums[i+1]) count++;
            else if (nums[i-1] > nums[i] && nums[i] > nums[i+1]) count++;
        }
        
        System.out.println(count);
    }
} Main public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] nums = new int[n];
        String[] s = br.readLine().split(" ");
        
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(s[i]);
        }
        
        int count = 0;
        for (int i = 1; i < n-1; i++) {
            if (nums[i-1] < nums[i] && nums[i] < nums[i+1]) count++;
            else if (nums[i-1] > nums[i] && nums[i] > nums[i+1]) count++;
        }
        
        System.out.println(count);
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] nums = new int[n];
        String[] s = br.readLine().split(" ");
        
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(s[i]);
        }
        
        int count = 0;
        for (int i = 1; i < n-1; i++) {
            if (nums[i-1] < nums[i] && nums[i] < nums[i+1]) count++;
            else if (nums[i-1] > nums[i] && nums[i] > nums[i+1]) count++;
        }
        
        System.out.println(count);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] nums = new int[n]; nums new int[n] n String[] s = br.readLine().split(" "); s br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(s[i]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            nums[i] = Integer.parseInt(s[i]);
        } {
            nums[i] = Integer.parseInt(s[i]);
        } nums[i] = Integer.parseInt(s[i]) nums[i] nums i Integer.parseInt(s[i]) Integer.parseInt Integer s[i] s i int count = 0; count 0 for (int i = 1; i < n-1; i++) {
            if (nums[i-1] < nums[i] && nums[i] < nums[i+1]) count++;
            else if (nums[i-1] > nums[i] && nums[i] > nums[i+1]) count++;
        } int i = 1; int i = 1; i 1 i < n-1 i n-1 n 1 i++ i++ i {
            if (nums[i-1] < nums[i] && nums[i] < nums[i+1]) count++;
            else if (nums[i-1] > nums[i] && nums[i] > nums[i+1]) count++;
        } {
            if (nums[i-1] < nums[i] && nums[i] < nums[i+1]) count++;
            else if (nums[i-1] > nums[i] && nums[i] > nums[i+1]) count++;
        } if (nums[i-1] < nums[i] && nums[i] < nums[i+1]) count++;
            else if (nums[i-1] > nums[i] && nums[i] > nums[i+1]) count++; nums[i-1] < nums[i] && nums[i] < nums[i+1] nums[i-1] < nums[i] nums[i-1] nums i-1 i 1 nums[i] nums i nums[i] < nums[i+1] nums[i] nums i nums[i+1] nums i+1 i 1 count++ count if (nums[i-1] > nums[i] && nums[i] > nums[i+1]) count++; nums[i-1] > nums[i] && nums[i] > nums[i+1] nums[i-1] > nums[i] nums[i-1] nums i-1 i 1 nums[i] nums i nums[i] > nums[i+1] nums[i] nums i nums[i+1] nums i+1 i 1 count++ count 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) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] nums = new int[n];
        String[] s = br.readLine().split(" ");
        
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(s[i]);
        }
        
        int count = 0;
        for (int i = 1; i < n-1; i++) {
            if (nums[i-1] < nums[i] && nums[i] < nums[i+1]) count++;
            else if (nums[i-1] > nums[i] && nums[i] > nums[i+1]) count++;
        }
        
        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] nums = new int[n];
        String[] s = br.readLine().split(" ");
        
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(s[i]);
        }
        
        int count = 0;
        for (int i = 1; i < n-1; i++) {
            if (nums[i-1] < nums[i] && nums[i] < nums[i+1]) count++;
            else if (nums[i-1] > nums[i] && nums[i] > nums[i+1]) count++;
        }
        
        System.out.println(count);
    }
} Main
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.awt.Point;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] nums = new int[n];
        String[] s = br.readLine().split(" ");
        
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(s[i]);
        }
        
        int count = 0;
        for (int i = 1; i < n-1; i++) {
            if (nums[i-1] < nums[i] && nums[i] < nums[i+1]) count++;
            else if (nums[i-1] > nums[i] && nums[i] > nums[i+1]) count++;
        }
        
        System.out.println(count);
    }
}



