


n,d = map(int,input().split())

t= list(map(int,input().split()))
t.sort()


if n==1:
    print(0)
else:
    h=999999999999
    for j in range(n):
        for k in range(j+1,n):
            if t[k]-t[j] <= d:
                if n-(k-j+1) < h:
                    h=n-(k-j+1)


    if h==999999999999:
        print(n-1)
    else:
        print(h)
