n, d = map(int, raw_input().strip().split())
arr = sorted(map(int, raw_input().strip().split()))
ans = n
for i in xrange(n):
    for j in xrange(i, n):
        if arr[j]-arr[i]<=d:
            ans=min(n-(j-i+1), ans)
        else:
            break
print ans