n, d = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()

i = 0
j = 1
l = 0
tl = 1

if n == 1:
	print(0)
	exit()

while True:
	if abs(a[i] - a[j]) <= d:
		tl += 1
		j += 1
	else:
		if tl > l:
			l = tl
		tl = 1
		i += 1
		j = i + 1

	if i >= n - 1 or j >= n:
		if tl > l:
			l = tl
		break


print(n - l)