from heapq import heappop, heappush

N, M = list(map(int, input().split()))

X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])



hq = []

ans, j = 0, 0



for i in range(1, M + 1):  # M - i 日後にするバイトを考える

    while (j < N) and (X[j][0] <= i):

        heappush(hq, -X[j][1])  # 候補の追加

        j += 1

    if len(hq):

        ans += -heappop(hq)  # 候補があるとき、候補から最大値を取り出す



print(ans)

from heapq import heappush, heappop



N, M = list(map(int, input().split()))

job = []



for i in range(N):

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

  job += [(a,b)]

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

ls = []

ans = 0

j = 0

a = -1

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

  while a<=i and j<len(job):

    a, b = job[j]

    if a>i:

      break

    heappush(ls, -b)

    j += 1

  if ls:

    x = (-1)*heappop(ls)

#    print(x, i)

    ans += x

print(ans)
from heapq import heappop, heappush

N, M = list(map(int, input().split()))
X = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
hq = []
ans, j = 0, 0
for i in range(1, M + 1):  # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i):
        heappush(hq, -X[j][1])  # 候補の追加
        j += 1
    if len(hq):
        ans += -heappop(hq)  # 候補があるとき、候補から最大値を取り出す
print(ans)

from heapq import heappush, heappop

N, M = list(map(int, input().split()))
job = []
for i in range(N):
    a, b = list(map(int, input().split()))
    job += [(a, b)]
job.sort(key=lambda x: x[0])
ls = []
ans = 0
j = 0
a = -1
for i in range(1, M + 1):
    while a <= i and j < len(job):
        a, b = job[j]
        if a > i:
            break
        heappush(ls, -b)
        j += 1
    if ls:
        x = (-1) * heappop(ls)
        #    print(x, i)
        ans += x
print(ans)

-from heapq import heappop, heappush +from heapq import heappush, heappop -X = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0]) -hq = [] -ans, j = 0, 0 -for i in range(1, M + 1):  # M - i 日後にするバイトを考える -    while (j < N) and (X[j][0] <= i): -        heappush(hq, -X[j][1])  # 候補の追加 +job = [] +for i in range(N): +    a, b = list(map(int, input().split())) +    job += [(a, b)] +job.sort(key=lambda x: x[0]) +ls = [] +ans = 0 +j = 0 +a = -1 +for i in range(1, M + 1): +    while a <= i and j < len(job): +        a, b = job[j] +        if a > i: +            break +        heappush(ls, -b) -    if len(hq): -        ans += -heappop(hq)  # 候補があるとき、候補から最大値を取り出す +    if ls: +        x = (-1) * heappop(ls) +        #    print(x, i) +        ans += x