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

# finding largest possible area
# range <= d

def find_upper(arr, lower, d):
	upper = lower
	for u in range(lower, len(arr)):
		if(arr[u] - arr[lower] <= d):
			upper = u
	return upper

max_range = 0
for j in range(n):
	this_upper = find_upper(arr, j, d) - j + 1
	# print(j, this_upper)
	max_range = max(max_range, this_upper)

print(n - max_range)
