n,d = list(map(int,input().split()))
x = list(map(int,input().split()))
x.sort()
j = 0
ans = 0
for i in range(n):
    while j < n and x[j] - x[i] <= d:
        j += 1
    if j == n or x[j] - x[i] > d:
        j -= 1
    ans = max(ans,j - i + 1)

print(n - ans)
