let () =
  Scanf.scanf "%d\n" @@ fun n ->
  let p = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d in
  let ans = ref 0 in
  for i = 1 to n - 2 do
    if p.(i-1) < p.(i) && p.(i) < p.(i+1) || p.(i+1) < p.(i) && p.(i) < p.(i-1)
    then ans := !ans + 1
  done;
  Printf.printf "%d\n" !ans