n,d = map(int,input().split())
ls = list(map(int,input().split()))
lens = len(ls)
ls.sort()
ans = 999999999999999999999999
for left in range(0,lens):
    for right in range(0,lens):
        if right<left:
            continue
        if ls[right] - ls[left] <= d:
            ans = min(lens-1 - right + left,ans)
print(ans)
	       	   	 	   	 	  		 	 	