n,d=map(int,input().split())
ns=list(map(int,input().split()))
nss=list(set(ns))
nss.sort()
nsss=[]
for i in nss:
    nsss+=[(i,ns.count(i))]
nn=len(nsss)
cons,mins=0,n
for i in range(nn):
    conts=0
    for j in range(i,nn):
        conts+=nsss[i][1]
        new=nsss[j][0]-nsss[i][0]
        if new>d:
            mins=min(mins,cons+conts)
        elif new==d:
            mins=min(mins,cons-nsss[i][1]+conts)
    cons+=nsss[i][1]
print(mins)
