def ii():
		return map(int, raw_input().split())

n,d = ii()
points = ii()
points.sort()
count = n
max1 = max(points)
min1 = min(points)
temp = 0
for ele in points:
	if (max1-ele) <= d:
		break
	else:
		temp += 1

count = min(count, temp)

temp = 0
for ele in points[::-1]:
	if (ele-min1) <= d:
		break
	else:
		temp += 1

count = min(count, temp)
print count