(* O(n) *)
let solve n a_s = List.fold_left max 0 a_s - List.fold_left min max_int a_s

let read_ints () = read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string

let _ =
  let n = read_int () in
  read_ints () |> solve n |> string_of_int |> print_endline