def main():
    n, d = map(int, input().split())
    l = sorted(map(int, input().split()))
    b, j, r = l[0], 0, 0
    for i, a in enumerate(l):
        if a - b > d:
            a -= d
            while a > l[j]:
                j += 1
            b = l[j]
        else:
            if r < i - j:
                r = i - j
    print(n - r - 1)


if __name__ == '__main__':
    main()
