import sys
# from io import StringIO
# sys.stdin = StringIO(open(__file__.replace('.py', '.in')).read())

n, d = list(map(int, input().split()))
a = list(map(int, input().split()))

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

a.sort()

m = 0

for i in range(n):
    c = 0
    for j in range(i+1, n):
        if a[j] - a[i] <= d:
            c += 1
        else:
            break
    m = max(m, 0 if c == 0 else c + 1)

if m == 0:
    print(n - 1)
else:
    print(n - m)
