import heapq



n,m = list(map(int,input().split()))



AB = [[int(i) for i in input().split()] for j in range(n)]



#ab.sort()



AB = sorted(AB, key=lambda x: x[0])



#print(ab)



tmp = 0

hq = []

ans = 0



for i in range(1,m+1):

    while tmp <= n-1 and AB[tmp][0] <= i:

        heapq.heappush(hq,-AB[tmp][1])

        tmp += 1

    if len(hq) > 0:

        ans += -heapq.heappop(hq)

        

print(ans)
from heapq import heappop,heappush



n,m = list(map(int,input().split()))



AB = [[int(i) for i in input().split()] for j in range(n)]



#ab.sort()



AB = sorted(AB, key=lambda x: x[0])



#print(ab)



tmp = 0

hq = []

ans = 0



for i in range(1,m+1):

    while tmp <= n-1 and AB[tmp][0] <= i:

        heappush(hq,-AB[tmp][1])

        tmp += 1

    if len(hq) > 0:

        ans += -heappop(hq)

        

print(ans)
import heapq

n, m = list(map(int, input().split()))
AB = [[int(i) for i in input().split()] for j in range(n)]
# ab.sort()
AB = sorted(AB, key=lambda x: x[0])
# print(ab)
tmp = 0
hq = []
ans = 0
for i in range(1, m + 1):
    while tmp <= n - 1 and AB[tmp][0] <= i:
        heapq.heappush(hq, -AB[tmp][1])
        tmp += 1
    if len(hq) > 0:
        ans += -heapq.heappop(hq)
print(ans)

from heapq import heappop, heappush

n, m = list(map(int, input().split()))
AB = [[int(i) for i in input().split()] for j in range(n)]
# ab.sort()
AB = sorted(AB, key=lambda x: x[0])
# print(ab)
tmp = 0
hq = []
ans = 0
for i in range(1, m + 1):
    while tmp <= n - 1 and AB[tmp][0] <= i:
        heappush(hq, -AB[tmp][1])
        tmp += 1
    if len(hq) > 0:
        ans += -heappop(hq)
print(ans)

-import heapq +from heapq import heappop, heappush -        heapq.heappush(hq, -AB[tmp][1]) +        heappush(hq, -AB[tmp][1]) -        ans += -heapq.heappop(hq) +        ans += -heappop(hq)