n,d=map(int,raw_input().split())
x=map(int,raw_input().split())
x.sort()
removenum=0
p=0
q=n-1
while(True):
    if x[q]-x[p]<=d:
        break
    else:
        if x[q]-x[p+1]<x[q-1]-x[p]:
            p+=1
            removenum+=1
        else:
            q-=1
            removenum+=1
print removenum