def read1():
	ent = input().split()
	line = input().split()
	return int(ent[1]), list(map(int, line))

def read2():
	n = int(input().split()[0])
	k = int(input().split()[0])
	A = int(input().split()[0])
	B = int(input().split()[0])
	#x = int(input().split())
	return n, k, A, B#, x


def f1(d,A):
	A.sort()
	j = 0
	cd = 1
	for i in range(len(A)):
		if A[i] - A[j] > d:
			if cd < i - j:
				cd = i - j
			j += 1
	print(len(A) - cd)

f1(*read1())

def f2(x, k, A, B):
	c = 0
	while x != 1: 
		if k > 1 and x % k == 0:
			x /= k
			c += B
		else:
			x -= 1
			c += A

	print (c)

#f2(*read2())

