n,d = map(int,input().split())
x = list(map(int,input().split()))

x.sort()
z = n
for i in range(n):
	y = 0
	for j in range(i,n):
		if (x[j]-x[i] <= d): 
			if n - (j -i)-1 < z: 
				z = n - (j -i)-1 

print(z)

