n,d=map(int,input().strip().split(' '))
a=list(map(int,input().split(' ')))
a=sorted(a)
count=10**9
Left=0
Right=0
while Left < n:
		while Right < n and  a[Right] - a[Left] <= d:
		  Right=Right+1

		
		count = min(count, Left + n - Right)

		Left=Left+1
	

print(count)