n, d = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
lo, ans, cur, idx = A[0], 1, 1, 0

A.sort()

for i in range(1, n):
    if (A[i] - lo) <= d:
        cur = cur + 1
    else:
        idx = idx + 1
        lo = A[idx]
        cur = cur - 1
        i = i - 1
    ans = max(ans, cur)

print(n - ans)
