n, d = map(int, raw_input().split())
a = map(int, raw_input().split())
a.sort()
ans = 0
for i in range(n):
    s = a[i]
    c = 0
    for j in range(i, n):
        if a[j] - s > d:
            break
        c += 1
    ans = max(ans, c)
print n - ans    
 