n , d = map(int,input().split())
point_array = list(map(int,input().split()))
point_array.sort()
max_len = 0
for i in range(0,n):
	for j in range(i+1,n):
		if (point_array[j] - point_array[i] <= d):
			if (j-i+1 > max_len ):
				max_len = j-i+1 
print(n-max_len)
