fl = input()
sl = input()

num_points, max_d = [int(x) for x in fl.split()]
points = sorted([int(x) for x in sl.split()])

first_p = 0
second_p = 1

points_to_rem = num_points - 2
min_points_to_rem = num_points

while second_p < num_points and first_p < num_points:
    dist = points[second_p] - points[first_p]

    if dist <= max_d:
        min_points_to_rem = min(min_points_to_rem, points_to_rem)
        second_p += 1
        points_to_rem -= 1

    if dist > max_d:
        first_p += 1
        points_to_rem += 1

print(min_points_to_rem)
