N, K = gets.split.map &:to_i
hash = Hash.new(0)

N.times {
    h = gets.to_i
    hash[h] += 1
}

Keys = hash.keys.sort

minDif = Keys.max - Keys.min

for i in 0...Keys.size do
    sum = 0
    flg = true
    for j in i...Keys.size do
        sum += hash[Keys[j]]
        if sum >= K then
            flg = false
            minDif = [minDif, Keys[j] - Keys[i]].min
            break
        end
    end
    break if flg
end

p minDif
