# coding=utf-8
n, d = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
best = 100000
for i in range(len(a)):
    for j in range(i, len(a)):
        if a[j] - a[i] <= d and (n - j + i-1) < best:
            best = (n - j + i - 1)

print(best)
