import heapq

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

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

work.sort()



cd = []

heapq.heapify(cd)

cnt = 0

ans = 0

# b, a

# aの条件

for k in range(m+1):

    # a = kの仕事をheappush



    for i in range(cnt, n):

        a, b = work[i]



        if a == k:

            heapq.heappush(cd, [-b, a])

        else:

            cnt = i

            break



        if i == n-1:

            cnt = n-1



    if not cd:

        continue

    ans -= heapq.heappop(cd)[0]

print(ans)





import heapq

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

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

work.sort()



cd = []

heapq.heapify(cd)

cnt = 0

ans = 0

# b, a

# aの条件

for k in range(m+1):

    # a = kの仕事をheappush



    for i in range(cnt, n):

        a, b = work[i]



        if a == k:

            heapq.heappush(cd, -b)

        else:

            cnt = i

            break



        if i == n-1:

            cnt = n-1



    if not cd:

        continue

    ans -= heapq.heappop(cd)

print(ans)





import heapq

n, m = list(map(int, input().split()))
work = [list(map(int, input().split())) for _ in range(n)]
work.sort()
cd = []
heapq.heapify(cd)
cnt = 0
ans = 0
# b, a
# aの条件
for k in range(m + 1):
    # a = kの仕事をheappush
    for i in range(cnt, n):
        a, b = work[i]
        if a == k:
            heapq.heappush(cd, [-b, a])
        else:
            cnt = i
            break
        if i == n - 1:
            cnt = n - 1
    if not cd:
        continue
    ans -= heapq.heappop(cd)[0]
print(ans)

import heapq

n, m = list(map(int, input().split()))
work = [list(map(int, input().split())) for _ in range(n)]
work.sort()
cd = []
heapq.heapify(cd)
cnt = 0
ans = 0
# b, a
# aの条件
for k in range(m + 1):
    # a = kの仕事をheappush
    for i in range(cnt, n):
        a, b = work[i]
        if a == k:
            heapq.heappush(cd, -b)
        else:
            cnt = i
            break
        if i == n - 1:
            cnt = n - 1
    if not cd:
        continue
    ans -= heapq.heappop(cd)
print(ans)

-            heapq.heappush(cd, [-b, a]) +            heapq.heappush(cd, -b) -    ans -= heapq.heappop(cd)[0] +    ans -= heapq.heappop(cd)