n, d = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

minCost = len(a)
for i in range(len(a)-1):
    for j in range(i+1, len(a)):
        if a[j]-a[i] <= d:
            cost = i+(len(a)-j-1)
            minCost = min(cost, minCost)
print (min(minCost, len(a)-1) if len(a) > 1 else 0)
