n,d=[int(x) for x in input().split()]
arr=[int(x) for x in input().split()]
arr.sort()
ans=1000000000000
for i in range(n):
    for j in range(i,n):
        if arr[j]-arr[i]<=d:
            #print(n-(j-i+1))
            ans=min(ans,n-(j-i+1))
print(ans)
            
        
        