from itertools import combinations
n,d = map(int, input().split())
n1 = n
a = list(map(int, input().split()))
ans = n-1
a.sort()
for i,j in combinations(range(n),2):
    if abs(a[i]-a[j])<=d:
        if ans>n-(abs(j-i)+1):
            ans = n-(abs(j-i)+1)
print (ans)