n, d = [int(s) for s in input().split(' ')]
x = [int(s) for s in input().split(' ')]
x.sort()
m = float('inf')
for i in range(n):
    for j in range(i, n):
        if x[j] - x[i] <= d:
            m = min(m, n - (j - i + 1))
print(m)
