n, d = [int(k) for k in input().split(' ')]
arr = sorted([int(k) for k in input().split(' ')])

gmin = 9999

for i in range(len(arr)):
	j = 0
	for j in range(i, len(arr)):
		if arr[j] - arr[i] > d:
			j = j - 1
			break
	if len(arr) - j + i - 1 < gmin:
		gmin = len(arr) - j + i - 1

print(gmin)
