inf = 0x3f3f3f3f3f3f3f3f
M = mod = 1000000007
mod2inv = 500000004
pt = lambda *a, **k: print(*a, **k, flush=True)
rd = lambda: map(int, input().split())
n, d = rd()
a = list(rd())
a.sort()
r = 0
for i in range(n):
    for j in range(i, n):
        if a[j] - a[i] > d:
            break;
        r = max(r, j - i + 1)
print(n - r)
