(defn solve [n m x-org]
  (let [x (sort x-org)
        s (first x)
        e (last x)]
    (cond
      (= n 1) (- e s)
      (= n m) 0
      :else
      (->> x
           (partition 2 1)
           (map #(- (last %) (first %)))
           sort
           reverse
           (take (dec n))
           (apply +)
           (- (- e s))))))

(defn str->int-vec [s]
  (map
   #(Integer/parseInt %)
   (clojure.string/split s #"\s+")))

(let [nm (str->int-vec (read-line))]
  (println
   (solve
    (first nm)
    (last nm)
    (str->int-vec (read-line)))))
