n, d = map(int, input().split())
A = sorted([int(i) for i in input().split()])

c = 0
L, R = 0, n - 1
while L < R and A[R] - A[L] > d:
    if A[R] - A[L + 1] < A[R - 1] - A[L]:
        L += 1
    else:
        R -= 1

print(n - R - 1 + L)
