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)
mins=n
for i in range(nn):
    conts=nsss[i][1]
    for j in range(i+1,nn):
        conts+=nsss[j][1]
        new=nsss[j][0]-nsss[i][0]
        if new>d:
            mins=min(mins,n+nsss[i][1]-conts)
        elif new==d:
            mins=min(mins,n-conts)
        else:
            mins=min(mins,n-conts)
            continue
        break
if mins==n:
    print(0)
else:
    print(mins)
