import Data.List
import Control.Monad

solver::[Int]->Int->Int
solver ls k = let st = sort ls in (minimum.(map (\(x,y)-> x-y)).(zip (drop (k-1) st))) st

main::IO()
main=do
  nk<-getLine
  let n:k:[]= map read (words nk)
  dat<-forM [1..n] (\_-> do
                    s<-getLine
                    return (read s))
  print (solver dat k)
