n, d = map(int, input().split())
a = sorted(list(map(int, input().split())))

l, r = 0, 0
res = n - 1
while l < n:
    while r < n and a[r] - a[l] <= d:
        r += 1
    res = min(res, n - (r - l))
    l += 1
print(res)