
n, d = list(map(int, input().split()))
a = list(map(int, input().split()))

a = sorted(a)

l = 0
r = 0
cur_d = a[r] - a[l]
max_num = 1

while r < len(a):
    
    if a[r] - a[l] <= d:
        # print(l, r, a[r]-a[l])
        max_num = max(max_num, r - l + 1)
        r += 1
    else:
        l += 1

print(len(a) - max_num)