in1 = input()
#in1 = '6 3'
#in2 = '1 3 4 6 9 10'

in_str = in1.split()
n = int(in_str[0])
diameter = int(in_str[1])

#points = sorted(list(map(int, in2.split())));
points = sorted(list(map(int, input().split())));

longest = 0
start = 0

for start in range(n):
    length = 0
    end = start
    while (diameter >= points[end] - points[start]) and (end < n - 1):
        end += 1
    if (diameter < points[end] - points[start]):
        length = end - start
    else:
        length = end - start + 1
    if length > longest:
        longest = length
        
print(n - longest)