(defn input []
  (let [[N K] (->> (clojure.string/split (read-line) #"\s")
                (map #(Integer/parseInt %)))]
   (letfn [(for-input [] (Integer/parseInt (read-line)))]
     (list N K (repeatedly N for-input)))))

(defn Christmas [[N K H]]
  (transduce
    (comp (map #(- (last %) (first %))))
    min
    (Integer/MAX_VALUE)
    (->> H
      sort
      (partition K 1))))

(defn Christmas2 [[N K H]]
  (->> H
    sort
    (partition K 1)
    (map #(- (last %) (first %)))
    (apply min)))

(->> (input)
  Christmas
  println)