n,k = map(int, raw_input().split())
l = map(int, raw_input().split())
l.sort()
ans = 1000
for i in range(n):
    for j in range(n-1,-1,-1):
        if l[j] - l[i] <= k:
            if i+n-j-1 < ans:
                ans = i+n-j-1
            break
print ans