n,d = map(int,raw_input().split(" "))
arr = map(int,raw_input().split(" "))
arr.sort()
ans = n
for l in range(n):
    for r in range(n)[::-1]:
        if arr[r] - arr[l] <= d:
            ans = min(ans,n-(r-l+1))
print ans


 	  	  	  		  	 	 		  						  	