import sys

def minp():
	return sys.stdin.readline().strip()

r = 0
n, d = map(int,minp().split())
a = sorted(map(int,minp().split()))
l = 0
r = 0
b = []
while l < n:
	while (r < n-1) and (a[r+1]-a[l] <= d):
		r += 1
	b.append(r-l+1)
	l += 1
print(n-max(b))