n, d = (int(x) for x in input().split())
a = sorted([int(x) for x in input().split()])
min = n
for i in range(n):
    for j in range(n - 1, i, -1):
        if a[j] - a[i] <= d and (n - j + i) < min:
            min = n - j + i
print(min - 1)