import bisect
n, d = map(int, input().split())
x = sorted(map(int, input().split()))
if x[-1]-x[0] <= d:
	print('0')
	exit()
res = n
for tst in range(n):
	ind = bisect.bisect_right(x, x[tst]+d)
	if ind <= tst:
		break
	res = min(res, tst+n-ind)
print(res)
