from bisect import bisect_right

n, k = map(int, raw_input().split())
ll = map(int, raw_input().split())

ll.sort()

mon = None
for i in xrange(n):
    ind = bisect_right(ll, ll[i]+k)
    removed = n-ind + i
    #print ll[i], ind, removed
    if mon is None or mon > removed:
        mon = removed

print mon