function Main(input) {
	var inputArr = input.split("\n");
	var knArr = inputArr[0].split(" ");
	var n = knArr[0];
	var k = knArr[1];
  　inputArr.shift();
  	var list = inputArr
    .filter(i => i !== '')
    .sort(function(a, b){
    	return b-a;
	});
	var max = 0;
    var min = 10000000000;
	for(var i = 0; i < k; i++) {
      var p = parseInt(list[i], 10);;
      max = p > max ? p : max;
      min = p < min ? p : min;
	}
    console.log(max - min);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));