def main():
    N, D = map(int, input().split())
    X = tuple(map(int, input().split()))

    cnt = []
    apnd = cnt.append
    x = sorted(X, reverse=1)
    for i in range(N - 1):
        for j in range(i + 1, N):
            if x[i] - x[j] <= D:
                apnd(i + (N - (j + 1)))

    if not cnt:
        print(N - 1)
    else:
        print(min(cnt))

main()
