import math

def inp():
    a = input().split()
    return list(map(int, a))

def C(R, x1, y1, x2, y2):
    dy = y2 - y1
    dx = x2 - x1
    l = math.sqrt(dx**2 + dy ** 2)
    if l == 0:
        print(x1, y1 + R/2, R/2)
        return 0
    if l > R:
        print(x1, y1, R)
        return 0
    r = (l + R) / 2
    c = R - r
    yp = dy / l * (l + c) -y2 + y1
    xp = (l + c) * dx / l - x2 + x1
    x = x1 - xp
    y = y1 - yp
    print (x, y, r)

#C(*inp())

def inpt():
    n = input().split()
    n, d = list(map(int, n))
    a = input().split()
    return n, d, list(map(int, a))

def multifind(n,d,A):
    A.sort()
    dmin = 0
    j = 0
    i = 0
    while i < n:
        mas = i - j + 1
        if A[i] - A[j] <= d:
            if mas > dmin:
                dmin = mas
        else:
            j += 1
            i -= 1
        i += 1
    print(n - dmin)

multifind(*inpt())