from heapq import heappush, heappop



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

X = [list(map(int, input().split())) for _ in range(N)]



pq = []

for a, b in X:

    heappush(pq, (a, b))

    

cand = []

ans = 0

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

    while pq:

        a, b = heappop(pq)

        if a <= t:

            heappush(cand, -b)

        else:

            heappush(pq, (a, b))

            break



    if cand:

        v = heappop(cand)

        ans += -v



print(ans)



from heapq import heappop, heappush



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

X = [list(map(int, input().split())) for _ in range(N)]



X.sort(reverse=True)

ans = 0

pq = []

for n in range(M + 1):

    while X and X[-1][0] <= n:

        a, b = X.pop()

        heappush(pq, -b)



    if pq:

        ans -= heappop(pq)



print(ans)

from heapq import heappush, heappop

N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
pq = []
for a, b in X:
    heappush(pq, (a, b))
cand = []
ans = 0
for t in range(1, M + 1):
    while pq:
        a, b = heappop(pq)
        if a <= t:
            heappush(cand, -b)
        else:
            heappush(pq, (a, b))
            break
    if cand:
        v = heappop(cand)
        ans += -v
print(ans)

from heapq import heappop, heappush

N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(reverse=True)
ans = 0
pq = []
for n in range(M + 1):
    while X and X[-1][0] <= n:
        a, b = X.pop()
        heappush(pq, -b)
    if pq:
        ans -= heappop(pq)
print(ans)

-from heapq import heappush, heappop +from heapq import heappop, heappush +X.sort(reverse=True) +ans = 0 -for a, b in X: -    heappush(pq, (a, b)) -cand = [] -ans = 0 -for t in range(1, M + 1): -    while pq: -        a, b = heappop(pq) -        if a <= t: -            heappush(cand, -b) -        else: -            heappush(pq, (a, b)) -            break -    if cand: -        v = heappop(cand) -        ans += -v +for n in range(M + 1): +    while X and X[-1][0] <= n: +        a, b = X.pop() +        heappush(pq, -b) +    if pq: +        ans -= heappop(pq)