n,d=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
mind=A[len(A)-1]-A[0]
mini=n
if(mind<=d):
	print(0)
else:
	cond=0
	for i in range(0,len(A)):
		for j in range(len(A)-1,i,-1):
			#print(A[j])
			if(A[j]-A[i]<=d):
				cond=1
				minde=i+len(A)-j-1
				if(minde<mini):
					mini=minde
				break
	if(cond==1):
		print(mini)
	else:
		print(n-1)