n, d  = list(map(int, input().split()))
x = list(map(int, input().split()))[:n]
x.sort()
res = n
for i in range(n):
    if i>1 and x[i] == x[i-1]:
        continue
    start  = i
    while start>0 and x[start-1] == x[i]:
        start -= 1
    finish = i
    while finish<n and x[finish] - x[i] <=d:
        finish += 1
    res = min(res, start + (n-finish))
print (res)