const inf = Number.MAX_SAFE_INTEGER;
function Main(input){
	input = input.split("\n");
	var mem = input[0].split(" ").map(Number);
	input.shift();
	input = input.sort(function(a,b){return a-b}); 
	var min = inf;
	for(var i=mem[1]-1;i<input.length;i++){
		if(min>input[i]-input[i-mem[1]+1]) min = input[i]-input[i-mem[1]+1];
	}
	console.log(min)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());