n,d = map(int, raw_input().strip().split(' '))
X = map(int, raw_input().strip().split(' '))
res = [n-1]*n
X = sorted(X)

for i in xrange(1,n) :
	tmp = X[i]-d
	ans = 0
	j = i-1
	while j>= 0 :
		if X[i]-X[j] > d :
			break
		j -= 1
	ans = j + 1
	res[i] = (ans+(n-1-i))
print min(res)