local N, K = io.read("n", "n")
local h = {}
for i=1, N do
    h[i] = io.read("n")
end
table.sort(h)
local lo = 1
local hi = K
local hmin, hmax = h[lo], h[hi]
local ugliness = hmax - hmin
local min_ugliness = ugliness
while hi + 1 <= N do
    local new_hmin = h[lo + 1]
    local new_hmax = h[hi + 1]
    local new_ugliness = new_hmax - new_hmin
    if new_ugliness < min_ugliness then
        min_ugliness = new_ugliness
    end
    lo = lo + 1
    hi = hi + 1
end
print(min_ugliness)
