n , d = [int(c) for c in input().split()]
a = [int(x) for x in input().split()]

a.sort()
f = a[0]
ans = 0
ans1 = 0
for i in range(n- 1, 0, -1):
    if a[i] - f > d:
        ans += 1
l = a[-1]
for i in range(n - 1):
    if l - a[i] > d:
        ans1 += 1
print(min(ans, ans1))
