from heapq import heappush, heappop



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

jobs = []

for i in range(n):

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

    jobs.append([a, b])



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



hq = []

res, j = 0, 0

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

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

        heappush(hq, -jobs[j][1])

        j += 1

    if len(hq) > 0:

        res += -heappop(hq)

print(res)
from heapq import heappush, heappop



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

jobs = [[] for _ in range(10 ** 5 + 100)]

# 隣接リストっぽく

for i in range(n):

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

    jobs[a].append(b)



hq = []

res, j = 0, 0

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

    for v in jobs[i]:

        heappush(hq, -v)

    if len(hq) > 0:

        res += -heappop(hq)

print(res)
from heapq import heappush, heappop

n, m = list(map(int, input().split()))
jobs = []
for i in range(n):
    a, b = list(map(int, input().split()))
    jobs.append([a, b])
jobs = sorted(jobs, key=lambda x: x[0])
hq = []
res, j = 0, 0
for i in range(1, m + 1):
    while j < n and jobs[j][0] <= i:
        heappush(hq, -jobs[j][1])
        j += 1
    if len(hq) > 0:
        res += -heappop(hq)
print(res)

from heapq import heappush, heappop

n, m = list(map(int, input().split()))
jobs = [[] for _ in range(10**5 + 100)]
# 隣接リストっぽく
for i in range(n):
    a, b = list(map(int, input().split()))
    jobs[a].append(b)
hq = []
res, j = 0, 0
for i in range(1, m + 1):
    for v in jobs[i]:
        heappush(hq, -v)
    if len(hq) > 0:
        res += -heappop(hq)
print(res)

-jobs = [] +jobs = [[] for _ in range(10**5 + 100)] +# 隣接リストっぽく -    jobs.append([a, b]) -jobs = sorted(jobs, key=lambda x: x[0]) +    jobs[a].append(b) -    while j < n and jobs[j][0] <= i: -        heappush(hq, -jobs[j][1]) -        j += 1 +    for v in jobs[i]: +        heappush(hq, -v)