n, d = map(int, input().split())
points = list(map(int, input().split()))
points.sort()
ans = n
for i in range(n):
    j = i
    while j<n and points[j] - points[i]<=d:
        j+=1
    ans = min(ans, n-(j-i))
print(ans)


