import std.stdio;
import std.algorithm;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{//try{
	auto tokens = split(my_readln());
	auto N = to!ulong(tokens[0]);
	auto K = to!ulong(tokens[1]);

	ulong[] trees;
	foreach (i; 0..N)
	{
		trees ~= to!ulong(my_readln());
	}
	trees.sort();
	ulong small = ulong.max;
	foreach (i; 0..N-(K-1))
	{
		auto diff = trees[i+K-1] - trees[i];
		if (diff < small) small = diff;
	}

	writeln(small);
	stdout.flush();
/*}catch (Throwable e)
	{
		writeln(e.toString());
	}
readln();*/
}