import copy

n, d = map(int, raw_input().split())
nums = map(int, raw_input().split())
nums.sort()
nums2 = copy.deepcopy(nums)

ans = n

def l(x):
    x.sort()
    return x[-1] - x[0]

while len(nums) >= 1:
    if l(nums) <= d:
        ans = min(ans, n - len(nums))
    nums.pop(0)

while len(nums2) >= 1:
    if l(nums2) <= d:
        ans = min(ans, n - len(nums2))
    nums2.pop()

print ans