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

ab_list=[]

for _ in range(n):

    a, b = list(map(int, input().split()))

    ab_list.append([a,b])

ab_list.sort()



import heapq

l = []

heapq.heapify(l)



ind=0

ans=0

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

    while n>ind and ab_list[ind][0] <= i:

        heapq.heappush(l,-ab_list[ind][1])

        ind+=1



    if len(l) !=0:

        b = -heapq.heappop(l)

        ans+=b

print(ans)
import sys

input=sys.stdin.readline



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

ab_list=[]

for _ in range(n):

    a, b = list(map(int, input().split()))

    ab_list.append([a,b])

ab_list.sort()



import heapq

l = []

heapq.heapify(l)



ind=0

ans=0

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

    while n>ind and ab_list[ind][0] <= i:

        heapq.heappush(l,-ab_list[ind][1])

        ind+=1



    if len(l) !=0:

        b = -heapq.heappop(l)

        ans+=b

print(ans)
n, m = list(map(int, input().split()))
ab_list = []
for _ in range(n):
    a, b = list(map(int, input().split()))
    ab_list.append([a, b])
ab_list.sort()
import heapq

l = []
heapq.heapify(l)
ind = 0
ans = 0
for i in range(1, m + 1):
    while n > ind and ab_list[ind][0] <= i:
        heapq.heappush(l, -ab_list[ind][1])
        ind += 1
    if len(l) != 0:
        b = -heapq.heappop(l)
        ans += b
print(ans)

import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
ab_list = []
for _ in range(n):
    a, b = list(map(int, input().split()))
    ab_list.append([a, b])
ab_list.sort()
import heapq

l = []
heapq.heapify(l)
ind = 0
ans = 0
for i in range(1, m + 1):
    while n > ind and ab_list[ind][0] <= i:
        heapq.heappush(l, -ab_list[ind][1])
        ind += 1
    if len(l) != 0:
        b = -heapq.heappop(l)
        ans += b
print(ans)

+import sys + +input = sys.stdin.readline