n, d = [int(x) for x in input().split()]
x = [int(x) for x in input().split()]

x.sort()

res = len(x)
for i in range(len(x)):
    j = i
    while j<len(x) and x[j] <= x[i]+d: j+=1
    res = min(res, len(x)-j+i)
print(res)
    
        
    
    
