n, d = map(int, raw_input().split())
val = map(int, raw_input().split())

val.sort()

def get_largest(l):
    biggest = 0
    for left in range(len(l)):
        l_item = l[left]
        size = 1
        idx = left + 1
        while idx < len(l) and l[idx] - l_item <= d:
            size += 1
            idx += 1
        biggest = max(biggest, size)
    return biggest

biggest = get_largest(val)

print(n - biggest)

