function Main(input){
  var N = input.split('\n')[0].split(' ')[0];
  var K = input.split('\n')[0].split(' ')[1];
  var h = input.split('\n');

  N = parseInt(N,10);
  K = parseInt(K,10);

  h.shift();

  for(i=0;i<N;i++){
    h[i] = parseInt(h[i],10);
  }

  h.sort((a,b)=>{

    return b - a;
  });

  var min ;

  for(i=0;i+(K-1)<N;i++){

    var a = h[i] - h[i+(K-1)];

    if(min === undefined){
      min = a;
    }else{
      if(min > a){
        min = a;
      }
    }

  }

  console.log(min);

  
}
  
Main(require("fs").readFileSync("/dev/stdin", "utf8"));