n,d=map(int,input().split())
a=[int(x) for x in input().split()]
a.sort()
ans=0
j=n-1
ans=0
i=0
mv=10000
for i in range(n):
	for j in range(i,n):
		if a[j]-a[i]<=d:
			if n-j+i-1<mv:
				mv=n-j+i-1
print(mv)