n, d = map(int, input().split())
a = list(map(int, input().split()))
lst = []
a.sort()
for i in range(n-1):
    for j in range(i+1, n):
        if a[j] - a[i] <= d:
            lst.append(n - j + i - 1)
if len(lst) == 0:
    print(0)
else :
    print(min(lst))
