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

ans = 1e18

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