n, d = map(int, input().split())
p = list(map(int, input().split()))
res = n- 1
p.sort()

for i in range(n):
    for j in range(i, n):
        if p[j] - p[i] > d:
            res = min(res, n -i-j +1)

print(res)