import heapq

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

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



ans = 0

can_work = []

i = 0

for m in range(M + 1):

    while (i < N) and (Work[i][0]) <= m:

        heapq.heappush(can_work, -Work[i][1])

        i += 1

    if can_work:

        ans += -heapq.heappop(can_work)



print(ans)

import heapq

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

works = sorted([list(map(int, input().split())) for i in range(N)])



ans = 0

hq = []

i = 0

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

    while (i < N) and (works[i][0] <= limit):

        cost, value = works[i]

        heapq.heappush(hq, -value)

        i += 1



    if hq:

        ans += -heapq.heappop(hq)



print(ans)

import heapq

N, M = list(map(int, input().split()))
Work = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: x[0])
ans = 0
can_work = []
i = 0
for m in range(M + 1):
    while (i < N) and (Work[i][0]) <= m:
        heapq.heappush(can_work, -Work[i][1])
        i += 1
    if can_work:
        ans += -heapq.heappop(can_work)
print(ans)

import heapq

N, M = list(map(int, input().split()))
works = sorted([list(map(int, input().split())) for i in range(N)])
ans = 0
hq = []
i = 0
for limit in range(1, M + 1):
    while (i < N) and (works[i][0] <= limit):
        cost, value = works[i]
        heapq.heappush(hq, -value)
        i += 1
    if hq:
        ans += -heapq.heappop(hq)
print(ans)

-Work = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: x[0]) +works = sorted([list(map(int, input().split())) for i in range(N)]) -can_work = [] +hq = [] -for m in range(M + 1): -    while (i < N) and (Work[i][0]) <= m: -        heapq.heappush(can_work, -Work[i][1]) +for limit in range(1, M + 1): +    while (i < N) and (works[i][0] <= limit): +        cost, value = works[i] +        heapq.heappush(hq, -value) -    if can_work: -        ans += -heapq.heappop(can_work) +    if hq: +        ans += -heapq.heappop(hq)