def main():
    n, d = map(int, input().split())
    x = sorted(int(c) for c in input().split())

    mn, mx = x[0], x[-1]

    diam = mx - mn
    if diam <= d:
        print(0)
        return

    res = []
    for i in range(n):
        for j in range(i+1, n):
            cnt = i + n - j - 1
            if x[j] - x[i] <= d:
                res.append(cnt)

    if res:
        print(min(res))
    else:
        print(n - 1)

    

if __name__ == '__main__':
    main()
