from heapq import heappop, heappush



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

byte = {}

for i in range(n):

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

    if a not in byte:

        byte[a] = []

    heappush(byte[a], [-b,a])



ans = 0

res = []

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

    if i in byte:

        heappush(res, heappop(byte[i]))

    if not res:

        continue

    b,a = heappop(res)

    ans -= b

    if byte[a]:

        heappush(res, heappop(byte[a]))

     

print(ans)
from heapq import heappop, heappush



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

byte = {}

for i in range(n):

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

    if a > m:

        continue

    if a not in byte:

        byte[a] = []

    heappush(byte[a], -b)



ans = 0

res = []

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

    if i in byte:

        while byte[i]:

            heappush(res, heappop(byte[i]))

    if res:

        ans -= heappop(res)

print(ans)
from heapq import heappop, heappush

n, m = list(map(int, input().split()))
byte = {}
for i in range(n):
    a, b = list(map(int, input().split()))
    if a not in byte:
        byte[a] = []
    heappush(byte[a], [-b, a])
ans = 0
res = []
for i in range(1, m + 1):
    if i in byte:
        heappush(res, heappop(byte[i]))
    if not res:
        continue
    b, a = heappop(res)
    ans -= b
    if byte[a]:
        heappush(res, heappop(byte[a]))
print(ans)

from heapq import heappop, heappush

n, m = list(map(int, input().split()))
byte = {}
for i in range(n):
    a, b = list(map(int, input().split()))
    if a > m:
        continue
    if a not in byte:
        byte[a] = []
    heappush(byte[a], -b)
ans = 0
res = []
for i in range(1, m + 1):
    if i in byte:
        while byte[i]:
            heappush(res, heappop(byte[i]))
    if res:
        ans -= heappop(res)
print(ans)

+    if a > m: +        continue -    heappush(byte[a], [-b, a]) +    heappush(byte[a], -b) -        heappush(res, heappop(byte[i])) -    if not res: -        continue -    b, a = heappop(res) -    ans -= b -    if byte[a]: -        heappush(res, heappop(byte[a])) +        while byte[i]: +            heappush(res, heappop(byte[i])) +    if res: +        ans -= heappop(res)