n, d = [int(s) for s in input().split()]
xs = sorted(int(s) for s in input().split())

if n == 1:
    print(0)
else:
    maxseg = 0
    for i in range(n):
        for j in range(i + 1, n):
            if xs[j] - xs[i] <= d:
                maxseg = max(maxseg, j - i + 1)
    print(n - maxseg)
