import sys
input = sys.stdin.readline
import math
############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
n,k=invr()
li=inlt()
li.sort()
tar1=li[0]+k
tar2=li[-1]-k
cnt1=0
cnt2=0
for i in li:
    if i > tar1:
        cnt1+=1
for i in li:
    if i<tar2:
        cnt2+=1
print(min(cnt1,cnt2))