n,k = gets.split.map &:to_i; h=[]
n.times do |i|
	h[i] = gets.to_i
end
h = h.sort; arr = Array.new(n-k+1).map{Array.new(3)}; ans = []
arr.length.times do |i|
	0.upto(2) do |j|
		arr[i][j] = h[i+j]
	end
	ans[i] = arr[i][2] - arr[i][0]
end
num = ans[0]
for i in 1..(ans.length-1) do
	if ans[i] < num
		num = ans
	end
end
puts num
