(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 (> (+ i K) (count H2))
       Min
       (let [Dif (- (nth H2 K2) (nth H2 i))]
         (if (zero? Dif)
           0
           (recur (unchecked-inc-int i) (min Dif Min))))))))

(->> (input)
  Christmas
  println)