n,k=map(int,input().split())
b=[0]*101
a=list(map(int,input().split()))
for i in a:
    b[i]+=1
c=max=0
for i in range(101-k):
    c=sum(b[i:i+k+1])
    if max<c:
        max=c
print(n-max)
    
        
        