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

l=[int(x) for x in input().split()]
l.sort()
ans=10**8
for i in range(n):
    for j in range(i+1,n):
        if l[j]-l[i]>d: 
            ans = min(ans, n - (j-i) )
            break
if ans==10**8:
    ans=0
print(ans)
