n, d = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]

arr = sorted(arr)

res = n
l = 0
r = 0

for i in range(n):
    for j in range(i, n):
        if (arr[j] - arr[i] <= d):
            res = min(res, i + (n - j) - 1)

'''
while (r < n):
    res = min(res, l + (n - r))
    
    r += 1
    while (r + 1 < n):
        if (arr[r + 1] - arr[l] > d):
            break;
        r += 1
    if (arr[r] - arr[l] > d):
        while (l ):
            l += 1
            if (arr[r] - arr[l + 1] <= d):
                break;
'''     
print(res)





