def binsearch(s,i,j,k):
    head=i
    tail=j
    while head+1<tail:
        #print(head,tail)
        curr=(head+tail)/2
        if s[tail]<k:return tail
        if s[head]>k:return head-1
        if s[curr]==k:return curr
        elif s[curr]>k:tail=curr
        elif s[curr]<k:head=curr
    if s[tail]==k:return tail
    return head
n,d=[int(i) for i in raw_input().split()]
l=[int(i) for i in raw_input().split()]
#l.sort()
count={}
for i in l:
    if i not in count:count[i]=0
    count[i]+=1
s=list(set(l))
s.sort()
mmin=len(l)
#print(count)
for i in range(len(s)):
    h=i
    e=binsearch(s,i,len(s)-1,s[i]+d)
    if s[e]>s[i]+d:e-=1
    z=0
    for j in range(0,i):z+=count[s[j]]
    for j in range(e+1,len(s)):z+=count[s[j]]
    mmin=min(mmin,z)
print(mmin)


  		 	  			  	 			   				 		  	