from math import *
n,d=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
x=inf
for i in range(n-1):
    for j in range(i+1,n):
        c=l[j]-l[i]
        if(c<=d):
            x=min(x,n-(j-i+1))
print(min(n-1,x))
