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

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

ans = 0

arr.sort()

for i in range(len(arr)):
    j = i
    tempJ = j
    while j in range(len(arr)):
        if arr[j] - arr[i] == d:
            tempJ = j
        elif arr[j] - arr[i] > d:
            break
        j += 1
        
    if arr[tempJ] - arr[i] == d and tempJ - i + 1 > ans:
        ans = tempJ - i + 1
    elif arr[tempJ] - arr[i] < d and ans == 0:
        ans = len(arr)
    elif arr[tempJ] - arr[i] > d and ans == 0:
        ans = len(arr) - 1
print(0 if len(arr) == 1 else len(arr) - ans)
        
