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

A.sort()

ans = 0

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

print(n - ans)