n,d = list(map(int,input().split()))
arr = list(map(int,input().split()))
arr.sort()
ans = n
l = 0
for r in range(n):
    while arr[r]-arr[l] > d and l < r:
        l+=1
    ans = min(ans, n - (r-l+1))
print(ans)