#!/bin/bash

read n
read p

function f() {
  for ((i=1; i < $n; i++)); do
    if [ $# -lt 3 ]; then break; fi
    if [ $1 -gt $2 -a $2 -gt $3 ] || [ $1 -lt $2 -a $2 -lt $3 ]; then
      (( count++ ))
    fi
    shift
  done
  echo $count
}

f $p