'''input
3 0
7 7 7
'''

n, d=[int(i) for i in input().split(" ")]
A=[int(i) for i in input().split(" ")]
A.sort()

ans=n
mi=A[0]
ma=A[-1]
l=0
r=0
for i in A:
	if i - mi>d:
		l+=1

for i in A:
	if ma-i>d:
		r+=1
print(min(l,r))