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

				  			 		 	 	 	  		 	 	 			