let () = Scanf.scanf "%d" @@ fun n ->
  let ps = Array.init n @@ fun _ -> Scanf.scanf " %d" Fun.id in
  let ids = Array.init (n - 2) @@ fun i -> i + 1 in
  let check acm id = if (ps.(id - 1) < ps.(id) && ps.(id) < ps.(id + 1)) || (ps.(id - 1) > ps.(id) && ps.(id) > ps.(id + 1)) 
                      then acm + 1 else acm in
  let ans = Array.fold_left check 0 ids in
  Printf.printf "%d\n" ans