program pastryshop;

const
    MAXN = 100000;
    
type elenco=array [0..MAXN-1] of Longint;

var
    D, K, N, i : LongInt;
    P          : elenco;
    

    
Procedure scambia (var a,b: longint);
var x:longint;
begin
   x:=a;
   a:=b;
   b:=x;
end;  
Procedure ordinamento (estremoi,estremos: Longint; var v : elenco; ordinato:boolean);
var inf, sup, medio:Longint;
    pivot :longint;
begin
    inf:=estremoi;
    sup:=estremos;
    medio:= (estremoi+estremos) div 2;
    pivot:=v[medio];
    repeat
      if (ordinato) then
         begin
            while (v[inf]<pivot) do  inf:=inf+1;
            while (v[sup]>pivot) do  sup:=sup-1;
         end;
      if inf<=sup then
       begin
         scambia(v[inf],v[sup]);
         inf:=inf+1;
         sup:=sup-1;
       end;
    until inf>sup;
    if (estremoi<sup) then ordinamento(estremoi,sup,v,ordinato);
    if (inf<estremos) then ordinamento(inf,estremos,v,ordinato);
end;


begin
{
    uncomment the two following lines if you want to read/write from files
    assign(input,  'input.txt');  reset(input);
    assign(output, 'output.txt'); rewrite(output);
}

    ReadLn(N, K);

    for i:=0 to N-1 do
        Read(P[i]);
    ReadLn();
    
    ordinamento (0,N-1,P,true);
   
    if K>=N-1 then D:=0 
              else
                begin
                  D:=P[N-K-1]-P[0]; 
                  for i:=1 to K do 
                             if P[i+(N-K)-1]-P[i]<D  then D:=P[i+(N-K)-1]-P[i];
                end;
                
    WriteLn(D);

end.
