n, d = [int(i) for i in input().split()]

x = [int(i) for i in input().split()]

# if d == 0:
#     print(0)
#     exit()

x.sort()

#print(x)

hsh = []
pos = 0
l = len(x)
tmp = -1

for i in range(101):

    if x[pos] == i:
        for pos1 in range(pos, l):
            if x[pos] == x[pos1]:
                tmp += 1
            else:
                break
        pos = pos1

    hsh.append(tmp)

    # if pos != l - 1 and x[pos + 1] <= i:
    #     pos += 1
    #
    # if pos > 0 and x[pos] == x[pos - 1]:
    #     hsh[-1] += 1
    #     i -= 1
    # else:
    #     hsh.append(pos)
    #
    # print(i)

#print(hsh)
mx = 0

for i in range(l):
    if x[i] + d > 100:
        break

    if hsh[x[i] + d] - i > mx:
        mx = hsh[x[i] + d] - i

    #print(mx)

print(l - mx - 1)
