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

            
        
        
        
        
    

        
