n,d=input().split()
n=int(n)
d=int(d)
l=[int(x) for x in input().split()]
l.sort()
mindel=0
mini=0
maxi=n-1
for i in range(n):
    for j in range(n-1, -1, -1):
        if abs(l[j]-l[i])<=d and abs(j-i)>mindel:
            mini=i
            maxi=j
            mindel=abs(j-i)
if abs(l[maxi]-l[mini])>d:
    print(n-1)
else:
    print(mini+n-maxi-1)