import heapq

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

job_list = []

for i in range(n):

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

    job_list.append((a,b))

job_list.sort(key=lambda x:x[0])

# print(job_list)



hq = []

max_income = 0

j = 0

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

    while j < n and job_list[j][0] <= i:

        heapq.heappush(hq, (-job_list[j][1],job_list[j][0]))

        j += 1

    if len(hq) < 1:

        continue

    b_i, a_i = heapq.heappop(hq)

    max_income += -b_i



print(max_income)
import sys

import heapq

input = sys.stdin.readline

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

job_list = []

for i in range(n):

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

    job_list.append((a,b))

job_list.sort(key=lambda x:x[0])

# print(job_list)



hq = []

max_income = 0

j = 0

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

    while j < n and job_list[j][0] <= i:

        heapq.heappush(hq, (-job_list[j][1],job_list[j][0]))

        j += 1

    if len(hq) < 1:

        continue

    b_i, a_i = heapq.heappop(hq)

    max_income += -b_i



print(max_income)
import heapq

n, m = list(map(int, input().split()))
job_list = []
for i in range(n):
    a, b = list(map(int, input().split()))
    job_list.append((a, b))
job_list.sort(key=lambda x: x[0])
# print(job_list)
hq = []
max_income = 0
j = 0
for i in range(1, m + 1):
    while j < n and job_list[j][0] <= i:
        heapq.heappush(hq, (-job_list[j][1], job_list[j][0]))
        j += 1
    if len(hq) < 1:
        continue
    b_i, a_i = heapq.heappop(hq)
    max_income += -b_i
print(max_income)

import sys
import heapq

input = sys.stdin.readline
n, m = list(map(int, input().split()))
job_list = []
for i in range(n):
    a, b = list(map(int, input().split()))
    job_list.append((a, b))
job_list.sort(key=lambda x: x[0])
# print(job_list)
hq = []
max_income = 0
j = 0
for i in range(1, m + 1):
    while j < n and job_list[j][0] <= i:
        heapq.heappush(hq, (-job_list[j][1], job_list[j][0]))
        j += 1
    if len(hq) < 1:
        continue
    b_i, a_i = heapq.heappop(hq)
    max_income += -b_i
print(max_income)

+import sys +input = sys.stdin.readline