import bisect 
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
if(a[-1]-a[0]<=k):
    print(0)
else:
    min_cnt=n
    cnt=0
    for i in range(n-1):
        min_cnt=min(min_cnt,n-1-bisect.bisect_right(a[i+1:],a[i]+k))
    for i in range(1,n):
        min_cnt=min(min_cnt,i-1+bisect.bisect_left(a[:n-i],a[-i]-k))
    print(min_cnt)


