n, d = map(int, raw_input().split())
l = map(int, raw_input().split())
l.sort()
ans = 1000000000000
for i in range(n):
	j = i 
	while j < n and l[j]-l[i] <= d:
		j += 1
	ans = min(ans, n- j + i)
print ans