n,d = tuple([int(item) for item in input().split(' ')])
arr = [ int(item) for item in input().split(' ')]
arr.sort()

l = 0
r = 0
minv = 1

while True:
    r = r+1
    if r == n:
        break
    while not (arr[r] - arr[l] <= d):
        l += 1 
    minv = max(minv, (r-l+1))

print(n-minv)
