n, d = map(int, input().split())

arr = list(map(int, input().split()))

ans = 0

arr.sort()

for i in range(len(arr)):
    
    found = False
    j = i
    tempJ = j
    while j in range(len(arr)):
        if arr[j] - arr[i] == d:
            found = True
            tempJ = j
        elif arr[j] - arr[i] > d:
            break
        j += 1
        
    if (found == True) and (tempJ - i + 1 > ans):
        ans = tempJ - i + 1

if len(arr) == 1:
    print(0)
elif ans == 0 and arr[n-1] >= d:
    print(len(arr) - 1)
elif ans == 0 and arr[n-1] < d:
    print(0)
else:
    print(len(arr) - ans)
        
