if __name__ == '__main__':
    n, d = map(int, input().split())
    numbers = list(map(int, input().split()))

    ma = 0
    # length = len(numbers)
    cnt = 0
    numbers = sorted(numbers)
    mean = sum(numbers) / len(numbers)
    while True:
        if max(numbers) - min(numbers) > d:
            if numbers[len(numbers) - 1] - mean > mean - numbers[0]:
                numbers.remove(numbers[len(numbers) - 1])
                cnt += 1
            else:
                numbers.remove(numbers[0])
                cnt += 1
        else:
            break
    # for i in range(n):
    #     cnt = 0
    #     pos = i
    #     while numbers[pos] <= numbers[i] + d and pos < n:
    #         pos += 1
    #         cnt += 1
    #     ma = max(ma, cnt)
    print(cnt)