from fractions import gcd
from math import factorial, ceil, sqrt, atan2, log, pi, e, asin,acos, cos, sin
from itertools import *
from fractions import Fraction
import string
import copy
import random
import bisect
from decimal import *
def id_generator(size=20, chars=string.digits):
    return ''.join(random.choice(chars) for _ in range(size))
 
def mp():
    return map(int,str(raw_input()).split())


n,d=mp()
l=list(mp())
l.sort()

ans=10**18
for i in range(n):
	j=i+1
	while j<n:
		if (l[j]-l[i])>d :
			break
		j+=1
	ans=min(ans,n-(j-i))

if ans==10**18:
	print 0
else:
	print ans