n,d = map(int,input().split())
lis = sorted(map(int,input().split()))
ans=0
for i in range(n):
    for j in range(n):
        if lis[j]-lis[i]<=d:
            ans=max(ans,j-i+1)
print(n-ans)
            