n, d = map(int,raw_input().split())
a = sorted(map(int,raw_input().split()))
ans = -10**10
for i in range(n):
	for j in range(i,n):
		if a[j] - a[i] > d:
			ans = max(ans, j-i)
			# print ans, a[j], a[i]
			break
if ans == -10**10:
	print 0
else:print n-ans