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

r = n

for p in range(n):
    q = n-1
    while a[q] - a[p] > d:
        q -= 1
    if n - (q - p + 1) < r:
        r =  n - (q - p + 1)
print(r)