n, d = map(int, input().split())
temp = [int(x) for x in input().split()]
temp.sort()
if temp[-1] - temp[0] <= d:
    print(0)
else:
    line = []
    for i in range(n-1):
        for j in range(i+1, n):
            #print(temp[i])
            #print(temp[j])
            if temp[j] - temp[i] > d:
                line.append(j-i)
                break
            elif j == n-1:
                line.append(j-i+1)
    print(n-max(line))
    #print(line)
