from collections import Counter

n, d = map(int, input().split())
x = list(map(int, input().split()))

c = Counter(x)
l = sorted(c.keys())

a, b = 0, 1
s_d = 0
s_p = c[l[0]]
m = c[l[0]]

ln = len(l)

for i in range(2 * ln):
    if s_d < d:
        if b < ln:
            s_d += l[b] - l[b - 1]
            s_p += c[l[b]]
            b += 1

        if s_d <= d:
            m = max(m, s_p)

    elif a + 1 < ln:
        s_d -= l[a + 1] - l[a]
        s_p -= c[l[a]]
        a += 1

print(n - m)
