open Scanf
open Printf
open Array

let rv f p q = f q p

let () = scanf " %d %d" @@ fun n m ->
  let a = init m (fun _ -> scanf " %d" @@ fun v -> v) in
  sort compare a;
  let d = init (m-1) (fun i -> abs @@ a.(i+1) - a.(i)) in
  sort (rv compare) d;
  print_int @@
    if n >= m then 0
    else fst @@ fold_left (fun (sum,i) v ->
      if i>=n-1 then (sum+v,i+1) else (sum,i+1)
    ) (0,0) d