from heapq import *

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

a = [[int(i) for i in input().split()] for _ in range(n)]

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

ans = 0

PQ = []

heapify(PQ)

idx = 0

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

    while idx < n and a[idx][0] <= i:

        heappush(PQ,-a[idx][1])

        idx += 1

    if PQ: ans -= heappop(PQ)

print(ans)
from heapq import heappop,heappush

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

lst = [[int(i) for i in input().split()] for _ in range(n)]

PQ = []

idx = 0

ans = 0

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

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

    while idx < n and lst[idx][0] <= i:

        heappush(PQ,-(lst[idx][1]))

        idx += 1

    if PQ: ans -= heappop(PQ)

print(ans)
from heapq import *

n, m = list(map(int, input().split()))
a = [[int(i) for i in input().split()] for _ in range(n)]
a.sort(key=lambda x: x[0])
ans = 0
PQ = []
heapify(PQ)
idx = 0
for i in range(1, m + 1):
    while idx < n and a[idx][0] <= i:
        heappush(PQ, -a[idx][1])
        idx += 1
    if PQ:
        ans -= heappop(PQ)
print(ans)

from heapq import heappop, heappush

n, m = list(map(int, input().split()))
lst = [[int(i) for i in input().split()] for _ in range(n)]
PQ = []
idx = 0
ans = 0
lst.sort(key=lambda x: x[0])
for i in range(1, m + 1):
    while idx < n and lst[idx][0] <= i:
        heappush(PQ, -(lst[idx][1]))
        idx += 1
    if PQ:
        ans -= heappop(PQ)
print(ans)

-from heapq import * +from heapq import heappop, heappush -a = [[int(i) for i in input().split()] for _ in range(n)] -a.sort(key=lambda x: x[0]) +lst = [[int(i) for i in input().split()] for _ in range(n)] +PQ = [] +idx = 0 -PQ = [] -heapify(PQ) -idx = 0 +lst.sort(key=lambda x: x[0]) -    while idx < n and a[idx][0] <= i: -        heappush(PQ, -a[idx][1]) +    while idx < n and lst[idx][0] <= i: +        heappush(PQ, -(lst[idx][1]))