Scanf.scanf "%d %d" @@ fun n m ->
let xs = Array.init m (fun _ -> Scanf.scanf " %d" ((+) 0)) in
Array.sort (-) xs;
let ds = Array.init (m-1) (fun i -> xs.(i+1) - xs.(i)) in
Array.sort (-) ds;
Array.sub ds 0 (max 0 @@ m-n) |> Array.fold_left (+) 0
|> Printf.printf "%d\n"