n, d = map(int, input().split(" "))
arr = list(map(int, input().split(" ")))

arr = sorted(arr)
break_flag = False
ans = 1e9

for i in range(0, n):
	for j in reversed(range(i, n)):
		currentDim = arr[j] - arr[i]
		if(currentDim <= d):
			ans = min(ans, n - (j - i + 1))

print(ans)