n,d=map(int,raw_input().split())
a=list(map(int,raw_input().split()))
a.sort()
ans=n
for i in range(n):
    for j in range(i,n):
        if a[j]-a[i]<=d:
            ans=min(ans,n-(j-i+1))
print ans
            
