import copy

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

ans = 0

for i in xrange(0, n):
    for j in xrange(i, n):
        if nums[j] - nums[i] <= d:
            ans = max(ans, j - i + 1)

print n - ans