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

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()))

    if a in job_list:

        job_list[a].append((-b,a))

    else:

        job_list[a] = [(-b,a)]

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

# print(job_list)



hq = []

max_income = 0

# j = 0

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

    if i in job_list:

        for j in job_list[i]:

            heapq.heappush(hq, j)

    # 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
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()))
    if a in job_list:
        job_list[a].append((-b, a))
    else:
        job_list[a] = [(-b, a)]
# job_list.sort(key=lambda x:x[0])
# print(job_list)
hq = []
max_income = 0
# j = 0
for i in range(1, m + 1):
    if i in job_list:
        for j in job_list[i]:
            heapq.heappush(hq, j)
    # 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)

-job_list = [] +job_list = {} -    job_list.append((a, b)) -job_list.sort(key=lambda x: x[0]) +    if a in job_list: +        job_list[a].append((-b, a)) +    else: +        job_list[a] = [(-b, a)] +# job_list.sort(key=lambda x:x[0]) -j = 0 +# j = 0 -    while j < n and job_list[j][0] <= i: -        heapq.heappush(hq, (-job_list[j][1], job_list[j][0])) -        j += 1 +    if i in job_list: +        for j in job_list[i]: +            heapq.heappush(hq, j) +    # while j < n and job_list[j][0] <= i: +    # heapq.heappush(hq, (-job_list[j][1],job_list[j][0])) +    # j += 1