# http://codeforces.com/contest/940/problem/A

import sys

n_and_d = sys.stdin.readline()
tmp = n_and_d.split(' ')
n = int(tmp[0])
d = int(tmp[1])

l = sys.stdin.readline().strip().split(' ')
l = [int(l[i]) for i in range(0, n)]

l.sort()

min = n

for i in range(0, n):
    upper_bound_value = l[i] + d
    upper_bound_index = i

    while upper_bound_index + 1 < n and l[upper_bound_index + 1] <= upper_bound_value:
        upper_bound_index += 1

    tmp = n - 1 - upper_bound_index + i;

    if tmp < min:
        min = tmp

print(min)