import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class No116 { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] str = br.readLine().split(" "); int[] num = new int[n]; for(int i=0; i < n; i++) num[i] = Integer.parseInt(str[i]); System.out.println(judge(num)); } public static int judge(int[] a){ int ans = 0; for(int i=1; i < a.length - 1; i++){ if(a[i-1] != a[i] && a[i-1] != a[i+1] && a[i] != a[i+1]){ if(!(a[i-1] > a[i] && a[i] > a[i+1]) && !(a[i-1] < a[i] && a[i] < a[i+1])){ ans++; } } } return ans; } }