#最終日から見る，残り日数条件を満たす中で最大収入のものを選ぶ



import heapq



N,M=list(map(int,input().split()))

AB=[[0,0] for _ in range(N)]



for i in range(N):

    AB[i][0],AB[i][1] = list(map(int,input().split()))



AB.sort()



ans=0

q=[]

heapq.heapify(q)

ne=0

#dは残り日数

for d in range(1,M+1):

    for i in range(ne,N):

        if AB[i][0]<=d:

            heapq.heappush(q,AB[i][1]*-1)

            ne=i+1

        else:

            break

    if len(q)!=0:

        a=heapq.heappop(q)

        ans-=a

    

print(ans)
import sys

input = sys.stdin.readline



def I(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))



def main():

    import heapq

    mod=10**9+7

    N,M=MI()

    L=[[]for _ in range(M)]

    for i in range(N):

        #何日までに受ける必要があるかを気にしながら持つ

        a,b=MI()

        if a<=M:

            L[M-a].append(-b)

        

    ans=0

    hq=[]

    heapq.heapify(hq)

    

    for i in range(M-1,-1,-1):

        for bb in L[i]:

            heapq.heappush(hq,bb)

            

        if len(hq)!=0:

            temp=heapq.heappop(hq)

            ans+=-1*temp

        

    print(ans)

        

        



main()

# 最終日から見る，残り日数条件を満たす中で最大収入のものを選ぶ
import heapq

N, M = list(map(int, input().split()))
AB = [[0, 0] for _ in range(N)]
for i in range(N):
    AB[i][0], AB[i][1] = list(map(int, input().split()))
AB.sort()
ans = 0
q = []
heapq.heapify(q)
ne = 0
# dは残り日数
for d in range(1, M + 1):
    for i in range(ne, N):
        if AB[i][0] <= d:
            heapq.heappush(q, AB[i][1] * -1)
            ne = i + 1
        else:
            break
    if len(q) != 0:
        a = heapq.heappop(q)
        ans -= a
print(ans)

import sys

input = sys.stdin.readline


def I():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def LI():
    return list(map(int, input().split()))


def main():
    import heapq

    mod = 10**9 + 7
    N, M = MI()
    L = [[] for _ in range(M)]
    for i in range(N):
        # 何日までに受ける必要があるかを気にしながら持つ
        a, b = MI()
        if a <= M:
            L[M - a].append(-b)
    ans = 0
    hq = []
    heapq.heapify(hq)
    for i in range(M - 1, -1, -1):
        for bb in L[i]:
            heapq.heappush(hq, bb)
        if len(hq) != 0:
            temp = heapq.heappop(hq)
            ans += -1 * temp
    print(ans)


main()

-# 最終日から見る，残り日数条件を満たす中で最大収入のものを選ぶ -import heapq +import sys -N, M = list(map(int, input().split())) -AB = [[0, 0] for _ in range(N)] -for i in range(N): -    AB[i][0], AB[i][1] = list(map(int, input().split())) -AB.sort() -ans = 0 -q = [] -heapq.heapify(q) -ne = 0 -# dは残り日数 -for d in range(1, M + 1): -    for i in range(ne, N): -        if AB[i][0] <= d: -            heapq.heappush(q, AB[i][1] * -1) -            ne = i + 1 -        else: -            break -    if len(q) != 0: -        a = heapq.heappop(q) -        ans -= a -print(ans) +input = sys.stdin.readline + + +def I(): +    return int(eval(input())) + + +def MI(): +    return list(map(int, input().split())) + + +def LI(): +    return list(map(int, input().split())) + + +def main(): +    import heapq + +    mod = 10**9 + 7 +    N, M = MI() +    L = [[] for _ in range(M)] +    for i in range(N): +        # 何日までに受ける必要があるかを気にしながら持つ +        a, b = MI() +        if a <= M: +            L[M - a].append(-b) +    ans = 0 +    hq = [] +    heapq.heapify(hq) +    for i in range(M - 1, -1, -1): +        for bb in L[i]: +            heapq.heappush(hq, bb) +        if len(hq) != 0: +            temp = heapq.heappop(hq) +            ans += -1 * temp +    print(ans) + + +main()