n, d = [int(i) for i in raw_input().split()]
p = [int(i) for i in raw_input().split()]
p.sort()
c = 0
if (n == 1):
    print 0
else:
    i = 0
    maxs = 0
    for j in xrange(n):
        if (p[j] - p[i] <= d):
            maxs = max(j - i, maxs)
        else:
            while ((p[j] - p[i] > d)):
                i += 1
            maxs = max(j - i, maxs)
        j += 1
    print n - maxs - 1
