(set! *unchecked-math* true)

(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]]
  (let [H2 (vec (sort H))
        K2 (dec K)]
   (loop [i 0 Min (Integer/MAX_VALUE)]
     (if (< N (+ i K))
       Min
       (let [Dif (int (- (nth H2 (+ i K2)) (nth H2 i)))]
         (if (zero? Dif)
           0
           (recur (inc i) (min Dif Min))))))))

(defn Christmas2 [[N K H]]
  (let [K2 (unchecked-dec-int K)]
    (loop [H2 (sort H) Min (Integer/MAX_VALUE)]
      (if (> K (count H2))
        Min
        (let [Dif (unchecked-subtract-int (nth H2 K2) (first H2))]
          (if (zero? Dif)
            0
            (recur (rest H2) (min Dif Min))))))))

(->> (input)
  Christmas
  println)