n,d = map(int,input().split())
a=list(map(int,input().split()))
a.sort();
i=0
cnt=0
cnt1=0
if n==1:
    print("0")

else:
    for i in range(n):
        cnt=0
        for j in range(i+1,n):
            d1=a[j]-a[i]
            if d1>d:
                break;
            cnt+=1
        if(cnt1<cnt):
            cnt1=cnt
    print(n-cnt1-1)