from sys import stdin, stdout
ti = lambda : stdin.readline().strip()
ma = lambda fxn, ti : map(fxn, ti.split())
ol = lambda arr : stdout.write(' '.join(str(i) for i in arr) + '\n')
os = lambda i : stdout.write(str(i) + '\n')
olws = lambda arr : stdout.write(''.join(str(i) for i in arr) + '\n')

n, d = ma(int, ti())
x = ma(int, ti())
x.sort(reverse=True)
if n == 1:
	os(0)
	exit()

if d == 0:
	from collections import Counter
	d = Counter(x)
	ans = -1
	for key in d.iterkeys():
		ans = max(ans, d[key])
	os(n-ans)
	exit()

ans = n-1
i = 0
while i < n:
	temp = 0
	j = i
	while j < n and x[i] - x[j] <= d:
		temp += 1
		j += 1
	ans = min(ans, n-temp)
	i += 1

os(ans)