n,d = [int(i) for i in input().split()]
e = [int(i) for i in input().split()]
e.sort()
w = 0
for i in range(n):
    j = i
    while j < n and e[j] - e[i] <= d:
        j += 1
    if w < j - i:
        w = j - i
print(n - w)