import heapq

maxB = 10 ** 1



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

AB = []

for _ in range(N):

    A, B = list(map(int, input().split()))

    AB.append((maxB - B, A))



AB.sort(key=lambda x: x[1])



ans, heap, idx, lAB = 0, [], 0, len(AB)

for i in range(M):

    while idx < lAB and AB[idx][1] <= i + 1:

        heapq.heappush(heap, AB[idx])

        idx += 1

    if len(heap) > 0:

        ans += maxB - heapq.heappop(heap)[0]



print(ans)

import heapq



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

AB = {i + 1: [] for i in range(10 ** 5)}

for _ in range(N):

    A, B = list(map(int, input().split()))

    AB[A].append(B)



ans, h = 0, []

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

    for b in AB[i]:

        heapq.heappush(h, -b)

    if len(h) > 0:

        ans -= heapq.heappop(h)



print(ans)

import heapq

maxB = 10**1
N, M = list(map(int, input().split()))
AB = []
for _ in range(N):
    A, B = list(map(int, input().split()))
    AB.append((maxB - B, A))
AB.sort(key=lambda x: x[1])
ans, heap, idx, lAB = 0, [], 0, len(AB)
for i in range(M):
    while idx < lAB and AB[idx][1] <= i + 1:
        heapq.heappush(heap, AB[idx])
        idx += 1
    if len(heap) > 0:
        ans += maxB - heapq.heappop(heap)[0]
print(ans)

import heapq

N, M = list(map(int, input().split()))
AB = {i + 1: [] for i in range(10**5)}
for _ in range(N):
    A, B = list(map(int, input().split()))
    AB[A].append(B)
ans, h = 0, []
for i in range(1, M + 1):
    for b in AB[i]:
        heapq.heappush(h, -b)
    if len(h) > 0:
        ans -= heapq.heappop(h)
print(ans)

-maxB = 10**1 -AB = [] +AB = {i + 1: [] for i in range(10**5)} -    AB.append((maxB - B, A)) -AB.sort(key=lambda x: x[1]) -ans, heap, idx, lAB = 0, [], 0, len(AB) -for i in range(M): -    while idx < lAB and AB[idx][1] <= i + 1: -        heapq.heappush(heap, AB[idx]) -        idx += 1 -    if len(heap) > 0: -        ans += maxB - heapq.heappop(heap)[0] +    AB[A].append(B) +ans, h = 0, [] +for i in range(1, M + 1): +    for b in AB[i]: +        heapq.heappush(h, -b) +    if len(h) > 0: +        ans -= heapq.heappop(h)