import java.io.*;
import 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 count = 0;
        int [] copyP = new int [3];
        for(int i=1;i<n-1;i++){
            copyP[0]= p[i-1];
            copyP[1]= p[i];
            copyP[2]= p[i+1];
            quick_sort(copyP,0,2);
            if(copyP[1]==p[i]){
                count++;
            }
        }
        System.out.println(count);
    }
    static void quick_sort(int[] d, int left, int right) {
        if (left >= right) {
            return;
        }
        int p = d[(left + right) / 2];
        int l = left, r = right, tmp;
        while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    }
} import java.io.*; io.* java import java.util.*; util.* java 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 count = 0;
        int [] copyP = new int [3];
        for(int i=1;i<n-1;i++){
            copyP[0]= p[i-1];
            copyP[1]= p[i];
            copyP[2]= p[i+1];
            quick_sort(copyP,0,2);
            if(copyP[1]==p[i]){
                count++;
            }
        }
        System.out.println(count);
    }
    static void quick_sort(int[] d, int left, int right) {
        if (left >= right) {
            return;
        }
        int p = d[(left + right) / 2];
        int l = left, r = right, tmp;
        while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    }
} 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 count = 0;
        int [] copyP = new int [3];
        for(int i=1;i<n-1;i++){
            copyP[0]= p[i-1];
            copyP[1]= p[i];
            copyP[2]= p[i+1];
            quick_sort(copyP,0,2);
            if(copyP[1]==p[i]){
                count++;
            }
        }
        System.out.println(count);
    } 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 count = 0;
        int [] copyP = new int [3];
        for(int i=1;i<n-1;i++){
            copyP[0]= p[i-1];
            copyP[1]= p[i];
            copyP[2]= p[i+1];
            quick_sort(copyP,0,2);
            if(copyP[1]==p[i]){
                count++;
            }
        }
        System.out.println(count);
    } 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 count = 0; count 0 int [] copyP = new int [3]; copyP new int [3] 3 for(int i=1;i<n-1;i++){
            copyP[0]= p[i-1];
            copyP[1]= p[i];
            copyP[2]= p[i+1];
            quick_sort(copyP,0,2);
            if(copyP[1]==p[i]){
                count++;
            }
        } int i=1; int i=1; i 1 i<n-1 i n-1 n 1 i++ i++ i {
            copyP[0]= p[i-1];
            copyP[1]= p[i];
            copyP[2]= p[i+1];
            quick_sort(copyP,0,2);
            if(copyP[1]==p[i]){
                count++;
            }
        } {
            copyP[0]= p[i-1];
            copyP[1]= p[i];
            copyP[2]= p[i+1];
            quick_sort(copyP,0,2);
            if(copyP[1]==p[i]){
                count++;
            }
        } copyP[0]= p[i-1] copyP[0] copyP 0 p[i-1] p i-1 i 1 copyP[1]= p[i] copyP[1] copyP 1 p[i] p i copyP[2]= p[i+1] copyP[2] copyP 2 p[i+1] p i+1 i 1 quick_sort(copyP,0,2) quick_sort copyP 0 2 if(copyP[1]==p[i]){
                count++;
            } copyP[1]==p[i] copyP[1] copyP 1 p[i] p i {
                count++;
            } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args static void quick_sort(int[] d, int left, int right) {
        if (left >= right) {
            return;
        }
        int p = d[(left + right) / 2];
        int l = left, r = right, tmp;
        while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    } quick_sort {
        if (left >= right) {
            return;
        }
        int p = d[(left + right) / 2];
        int l = left, r = right, tmp;
        while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    } if (left >= right) {
            return;
        } left >= right left right {
            return;
        } return; int p = d[(left + right) / 2]; p d[(left + right) / 2] d (left + right) / 2 (left + right) left right 2 int l = left l left r = right r right tmp; tmp while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        } l <= r l r {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        } while (d[l] < p) {
                l++;
            } d[l] < p d[l] d l p {
                l++;
            } l++ l while (d[r] > p) {
                r--;
            } d[r] > p d[r] d r p {
                r--;
            } r-- r if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            } l <= r l r {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            } tmp = d[l] tmp d[l] d l d[l] = d[r] d[l] d l d[r] d r d[r] = tmp d[r] d r tmp l++ l r-- r quick_sort(d, left, r) quick_sort d left r quick_sort(d, l, right) quick_sort d l right int[] d d int left left int right right 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 count = 0;
        int [] copyP = new int [3];
        for(int i=1;i<n-1;i++){
            copyP[0]= p[i-1];
            copyP[1]= p[i];
            copyP[2]= p[i+1];
            quick_sort(copyP,0,2);
            if(copyP[1]==p[i]){
                count++;
            }
        }
        System.out.println(count);
    }
    static void quick_sort(int[] d, int left, int right) {
        if (left >= right) {
            return;
        }
        int p = d[(left + right) / 2];
        int l = left, r = right, tmp;
        while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    }
} 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 count = 0;
        int [] copyP = new int [3];
        for(int i=1;i<n-1;i++){
            copyP[0]= p[i-1];
            copyP[1]= p[i];
            copyP[2]= p[i+1];
            quick_sort(copyP,0,2);
            if(copyP[1]==p[i]){
                count++;
            }
        }
        System.out.println(count);
    }
    static void quick_sort(int[] d, int left, int right) {
        if (left >= right) {
            return;
        }
        int p = d[(left + right) / 2];
        int l = left, r = right, tmp;
        while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    }
} Main
import java.io.*;
import 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 count = 0;
        int [] copyP = new int [3];
        for(int i=1;i<n-1;i++){
            copyP[0]= p[i-1];
            copyP[1]= p[i];
            copyP[2]= p[i+1];
            quick_sort(copyP,0,2);
            if(copyP[1]==p[i]){
                count++;
            }
        }
        System.out.println(count);
    }
    static void quick_sort(int[] d, int left, int right) {
        if (left >= right) {
            return;
        }
        int p = d[(left + right) / 2];
        int l = left, r = right, tmp;
        while (l <= r) {
            while (d[l] < p) {
                l++;
            }
            while (d[r] > p) {
                r--;
            }
            if (l <= r) {
                tmp = d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++;
                r--;
            }
        }
        quick_sort(d, left, r);
        quick_sort(d, l, right);
    }
}