n,d = map(int,input().split())
s = [int(i) for i in input().split()]
s.sort()
ans = 0

for i in range(n):
	cnt=0
	for j in range(n-1,-1,-1):
		if s[j]-s[i]<=d:
			cnt = j-i
			break
	ans=max(cnt+1,ans)
print(n-ans)