import heapq

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

AB = [[] for i in range(M+1)]

for i in range(N):

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

    if a <= M:

        AB[a].append(-b)

work = 0

AB2 = []

heapq.heapify(AB2)

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

    for j in AB[i]:

        heapq.heappush(AB2,j)

    if len(AB2) > 0:

        b = heapq.heappop(AB2)

        work += -b

print(work)
import sys

import heapq

input = sys.stdin.readline

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

AB = [[] for i in range(M+1)]

for i in range(N):

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

    if a <= M:

        AB[a].append(-b)

work = 0

AB2 = []

heapq.heapify(AB2)

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

    for j in AB[i]:

        heapq.heappush(AB2,j)

    if len(AB2) > 0:

        b = heapq.heappop(AB2)

        work += -b

print(work)
import heapq

N, M = list(map(int, input().split()))
AB = [[] for i in range(M + 1)]
for i in range(N):
    a, b = list(map(int, input().split()))
    if a <= M:
        AB[a].append(-b)
work = 0
AB2 = []
heapq.heapify(AB2)
for i in range(1, M + 1):
    for j in AB[i]:
        heapq.heappush(AB2, j)
    if len(AB2) > 0:
        b = heapq.heappop(AB2)
        work += -b
print(work)

import sys
import heapq

input = sys.stdin.readline
N, M = list(map(int, input().split()))
AB = [[] for i in range(M + 1)]
for i in range(N):
    a, b = list(map(int, input().split()))
    if a <= M:
        AB[a].append(-b)
work = 0
AB2 = []
heapq.heapify(AB2)
for i in range(1, M + 1):
    for j in AB[i]:
        heapq.heappush(AB2, j)
    if len(AB2) > 0:
        b = heapq.heappop(AB2)
        work += -b
print(work)

+import sys +input = sys.stdin.readline