import bisect
n, d = list(map(int, input().split()))
multiset = list(map(int, input().split()))
multiset.sort()
ans = 0
for i, x in enumerate(multiset):
    ans = max(ans, bisect.bisect_right(multiset, x+d) - i)
print(n - ans)
