import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;

void main() {
	auto data = readln.split, N = data[0].to!int, K = data[1].to!int;
	auto h = heapify!("a>b", int[])([]);
	foreach (i; 0 .. N) { h.insert(readln.split[0].to!int); }
	auto h_ = h.array;
	(N-K+1).iota.map!(x => h_[x+K-1]-h_[x]).reduce!"min(a, b)".writeln;
}