import sys

from heapq import heappush,heappop



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

ab = []

for line in sys.stdin:

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

    if a <= m:

        ab.append((a,b))

ab.sort()



stock = []

ans = 0

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

    while ab and ab[0][0] <= i:

        a,b = ab.pop(0)

        heappush(stock,-b)

    if stock:

        ans += -heappop(stock)



print(ans)
import sys

from heapq import heappush,heappop



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

ab = []

for line in sys.stdin:

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

    if a <= m:

        ab.append((a,b))

ab.sort(reverse=1)



stock = []

ans = 0

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

    while ab and ab[-1][0] <= i:

        a,b = ab.pop()

        heappush(stock,-b)

    if stock:

        ans += -heappop(stock)



print(ans)
import sys
from heapq import heappush, heappop

n, m = list(map(int, input().split()))
ab = []
for line in sys.stdin:
    a, b = list(map(int, line.split()))
    if a <= m:
        ab.append((a, b))
ab.sort()
stock = []
ans = 0
for i in range(1, m + 1):
    while ab and ab[0][0] <= i:
        a, b = ab.pop(0)
        heappush(stock, -b)
    if stock:
        ans += -heappop(stock)
print(ans)

import sys
from heapq import heappush, heappop

n, m = list(map(int, input().split()))
ab = []
for line in sys.stdin:
    a, b = list(map(int, line.split()))
    if a <= m:
        ab.append((a, b))
ab.sort(reverse=1)
stock = []
ans = 0
for i in range(1, m + 1):
    while ab and ab[-1][0] <= i:
        a, b = ab.pop()
        heappush(stock, -b)
    if stock:
        ans += -heappop(stock)
print(ans)

-ab.sort() +ab.sort(reverse=1) -    while ab and ab[0][0] <= i: -        a, b = ab.pop(0) +    while ab and ab[-1][0] <= i: +        a, b = ab.pop()