print((function (fh)
	local a,r,n,k = {},10^9,fh:read("*n"),fh:read("*n")-1
	for i=1,n do a[i]=fh:read("*n") end
	table.sort(a)
	for i=1,n-k do r=a[i+k]-a[i]<r and a[i+k]-a[i] or r end
	return r
end)(io.stdin))