n, k = gets.split.map(&:to_i)
heights = []
minimum = 100000000000000000000000000000
n.times do
  heights << gets.to_i
end

heights.combination(k).each do |set|
  diff = set.max - set.min
  if minimum > diff
    minimum = diff
  end
end

puts minimum