n, d = input().split()
d = int(d)
L = input().split()
for i in range(len(L)):
    L[i] = int(L[i])
L = sorted(L)
r = 1000000
for i in range(len(L)):
    for j in range(i,len(L)):
        if L[j]-L[i]<=d:
            if len(L)-len(L[i:j])-1<r:
                r = len(L)-len(L[i:j])-1
print(r)
        
