import sys

n, d = input().split(' ')
n = int(n)
d = int(d)

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

if n == 1:
    print('0')
    sys.exit()

A.sort()
kapa = 1000000000
for i in range(len(A)):
    for j in range(i, len(A)):
        zeta = A[j] - A[i]
        if zeta <= d and n - (j - i + 1) < kapa:
            kapa = n - (j - i + 1)

print(kapa)
