from heapq import heappush, heappop

from collections import defaultdict

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

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



cand = defaultdict(list)

for a, b in X:

    cand[a].append(b)



pq = []

ans = 0

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

    for c in cand[i]:

        heappush(pq, -c)

    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 heappush, heappop
from collections import defaultdict

N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
cand = defaultdict(list)
for a, b in X:
    cand[a].append(b)
pq = []
ans = 0
for i in range(1, M + 1):
    for c in cand[i]:
        heappush(pq, -c)
    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 collections import defaultdict -cand = defaultdict(list) +pq = [] -    cand[a].append(b) -pq = [] +    heappush(pq, (a, b)) +cand = [] -for i in range(1, M + 1): -    for c in cand[i]: -        heappush(pq, -c) -    if pq: -        ans -= heappop(pq) +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