n, d = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()

dia = arr[-1] - arr[0]
deletions = n - 1

for i in range(n):
    for j in range(i, n):
        temp_dia = arr[j] - arr[i]
        temp_del = i + n - 1 - j
        if temp_dia <= d and temp_del < deletions:
            dia = temp_dia
            deletions = temp_del

print(deletions)
