l=lambda:map(int,raw_input().split())
n,d=l()
a=l()
a.sort()
w=-1
for i in range(n):
    for j in range(i+1,n):
        if a[j]-a[i]>d:
            w=max(w,j-i)
            break
        if j==n-1:
            w=max(w,n-i)  
if w==-1:
    w=n
print n-w