n, d = map(int, raw_input().split())
a = map(int, raw_input().split())
a.sort()

def f(L, R):
	cnt = 0
	for i in xrange(L, R + 1):
		for j in xrange(L, R + 1):
			if i == j: continue
			if abs(a[i] - a[j]) > d:
				cnt += 1
	return cnt

lft = 0
rgt = n - 1
ans = 0
while True:
	if lft == rgt:
		break
	c0 = f(lft, rgt)
	if c0 == 0:
		break
	c1 = f(lft + 1, rgt)
	c2 = f(lft, rgt - 1)
	if c1 <= c2:
		lft += 1
		ans += 1
	else:
		rgt -= 1
		ans += 1
print ans
