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()))

byte = [[] for _ in range(100001)]



for _ in range(n):

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

    byte[a].append(b)

search = []

day = 1

ans = 0

while day-1 != m:

    for b in byte[day]:

        heapq.heappush(search, -b)

    if not search:

        day += 1

        continue

    tmp = -heapq.heappop(search)

    ans += tmp

    day += 1



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()))
byte = [[] for _ in range(100001)]
for _ in range(n):
    a, b = list(map(int, input().split()))
    byte[a].append(b)
search = []
day = 1
ans = 0
while day - 1 != m:
    for b in byte[day]:
        heapq.heappush(search, -b)
    if not search:
        day += 1
        continue
    tmp = -heapq.heappop(search)
    ans += tmp
    day += 1
print(ans)

-work = [list(map(int, input().split())) for _ in range(n)] -work.sort() -cd = [] -heapq.heapify(cd) -cnt = 0 +byte = [[] for _ in range(100001)] +for _ in range(n): +    a, b = list(map(int, input().split())) +    byte[a].append(b) +search = [] +day = 1 -# 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: +while day - 1 != m: +    for b in byte[day]: +        heapq.heappush(search, -b) +    if not search: +        day += 1 -    ans -= heapq.heappop(cd) +    tmp = -heapq.heappop(search) +    ans += tmp +    day += 1