n, d = map(int, input().strip().split())
x = list(map(int, input().strip().split()))
x.sort()

res = 1000000
for l in range(n):
    for r in range(l, n):
        cur = x[r] - x[l]
        if cur <= d:
            res = min(res, n - (r -l + 1))
print(res)