n,d = map(int, raw_input().split())
tab = map(int, raw_input().split())
if n == 1:
    print '0'
    exit(0)
wyn = 0
wyn_1 = 0
tab = sorted(tab)
for x in range(0, len(tab)-1, +1):
    wyn = 1
    for y in range(x+1, len(tab), +1):
        #print tab[x], tab[y]
        if abs(tab[x]-tab[y])<=d:
            #print tab[x], tab[y]
            wyn += 1
            #print wyn
            #print '------------------'
        else:
            if wyn > wyn_1:
                wyn_1 = wyn
            break
    if wyn > wyn_1:
        wyn_1 = wyn
print n-wyn_1