unittest
{
	assert( [ "5 3", "10", "15", "11", "14", "12" ].parse.expand.solve == 2 );
	assert( [ "5 3", "5", "7", "5", "7", "7" ].parse.expand.solve == 0 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	auto hs = new long[ nk[ 0 ] ];
	foreach( ref h; hs )
	{
		input.popFront;
		h = input.front.strip.to!( long );
	}
	return tuple( nk[ 1 ], hs );
}

auto solve( long k, long[] hs )
{
	hs.sort!( ( a, b ) => b < a );
	
	auto d = long.max;
	for( auto i = 0; i + k <= hs.length; i++ )
	{
		d = min( d, hs[ i ] - hs[ i + k - 1 ] );
	}
	return d;
}
