def dist(x, y):
    return abs(x - y)

def worker(m, M):
    '''
    naive implementation <-> Time Limit Excedded
    '''
    cnt1 = cnt2 = 0
    if (m < M and dist(unq[m], unq[M]) > diam):
        # print(m, M, dist(unq[m], unq[M]))
        cnt1 = freq[m] + worker(m + 1, M)
        cnt2 = freq[M] + worker(m, M - 1)
    return min(cnt1, cnt2)

if __name__=="__main__": 
    # GREEDY IS NOT GOOD [1,1,2,3,4,100] -> REMOVES {1, 1, 100} INSTEAD OF {100}
    # [n, diam] = [int(x) for x in input().split(' ')]
    # points = [int(x) for x in input().split(' ')]
    # unq = sorted(list(set(points))); print(unq)
    # freq = [len(list(filter(lambda x: x == i, points))) for i in unq]; print(freq)
    # m = 0; M = len(unq) -1; cnt = 0
    # while(dist(unq[m], unq[M]) > diam):
    #     if (freq[m] > freq[M]):
    #         cnt = cnt + freq[m]
    #         m = m + 1
    #     else:
    #         cnt = cnt + freq[M]
    #         M = M - 1
    #     print("set of points: ", unq[m:M+1])
    # print(cnt)


    # [n, diam] = [int(x) for x in input().split(' ')]
    # points = [int(x) for x in input().split(' ')]
    # unq = sorted(list(set(points)))
    # freq = [len(list(filter(lambda x: x == i, points))) for i in unq]
    # m = 0; M = len(unq) - 1
    
    # print(worker(m, M))


    [n, diam] = [int(x) for x in input().split(' ')]
    points = [int(x) for x in input().split(' ')]
    unq = sorted(list(set(points)))
    freq = [len(list(filter(lambda x: x == i, points))) for i in unq]
    m = 0; M = len(unq) - 1; cnt = 0
    j = lambda s: len(list(filter(lambda x: dist(x, unq[s]) > diam, unq[m: M + 1])))
    while(dist(unq[m], unq[M]) > diam):
        if (j(m) > j(M)):
            cnt = cnt + freq[m]
            m = m + 1
        else:
            cnt = cnt + freq[M]
            M = M - 1
        # print("set of points: ", unq[m:M+1])
    print(cnt)

