a=[*map(int,input().split(' '))]
b=[*map(int,input().split(' '))]
b=sorted(b)
c=0
d=0
e=0
f=len(b)
for i in range(0,f):
    for j in range(i,f):
        if(b[j]-b[i]>a[1]):
            c+=1
            i+=1
        if(j==f-1):
            break
    if(j==f-1):
        break
        
                    
print(c)
