import sys
n , d = map(int, input().split())

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

l.sort()

m = 0

for i in range(n):
    c = 0
    for z in range(i,n):
        if l[z] - l[i] > d:
            break

        c += 1

    m = max(m , c)

print(n-m)



