import math
n,d = map(int,input().split())
a = map(int,input().split())
a = sorted(list(a))
n = len(a)
ans=0
for i in range(n) :
	tot = 1
	for j in range(i+1,n):
		if a[j]-a[i] > d :
			break
		tot+=1
	ans = max(ans,tot)
print(n-ans)