n,d = map(int,input().split(' '))
x = input().split(' ')
x = [int(i) for i in x]
x = sorted(x)
if n == 1:
    print(0)
m = -1
for i in range(0,n):
    for j in range(0,n):
        if x[j]-x[i]<= d:
            m = max(m,j-i+1)
print(n - m)   