s = require("fs").readFileSync("/dev/stdin","utf8").split('\n')
n = s[0].split(' ')[0] | 0
k = s[0].split(' ')[1] | 0
s.shift()
s = s.map(n => n | 0).sort((a, b) => b - a)
a = 1000000000
for (i = 0; i < n - k + 1; i++) {
	ans = ans < s[i] - s[i + k - 1]
}
console.log(ans);
