let rec sum_k acc k ls =
  match k, ls with
  | 0, _ -> acc
  | _, [] -> acc
  | k, l::ls -> sum_k (l + acc) (k - 1) ls

let right (_, r) = r

let _ =
  let n, m = Scanf.scanf "%d %d\n" (fun n m -> n, m) in
  let xs = ref [] in
  let max_m, min_m = ref min_int, ref max_int in
  for i = 0 to m - 1 do
    Scanf.scanf (if i <> m - 1 then "%d " else "%d\n") (fun x -> xs := x::!xs);
    max_m := max !max_m (List.hd !xs);
    min_m := min !min_m (List.hd !xs)
  done;
  !xs
  |> List.sort compare
  |> (fun xs -> List.fold_left (fun (prev, acc) x -> (x, (x - prev)::acc)) 
                  (List.hd xs, []) @@ List.tl xs)
  |> right
  |> List.sort (fun x y -> 1 - (compare x y))
  |> sum_k 0 (n - 1)
  |> (fun ls -> (!max_m - !min_m) - ls)
  |> print_int