n, k = gets.split.map(&:to_i)
trees = []
n.times do
  trees << gets.to_i
end
trees.sort!
ans = Float::INFINITY
n.times do |i|
  break if trees[i+2].nil?
  diff = trees[i+2] - trees[i]
  ans = [ans, diff].min
end

puts ans