s=require("fs").readFileSync("/dev/stdin","utf8");
a = [...Array(s.split('\n')[0].split(' ')[0] | 0)].map((_, i) => s.split('\n')[i + 1] | 0)
a.sort()
l = s.split('\n')[0].split(' ')[1] - 1
b = [...Array(a.length - l)].map((_, i) => a[i + l] - a[i])
console.log(Math.min(...b));