#import sys
#sys.stdin = open('in.txt', 'r')
n, d = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
#print(a)
ans = 10000
for i in range(0,n):
    for j in range(i+1,n):
        if abs(a[j]-a[i]) <= d:
            ans = min(ans,n-(j+1)+i)
if ans == 10000:
    print(n-1)
else:
    print(ans)
