import heapq



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

jobs = [[] for _ in range(M+1)]

for _ in range(N):

    day, value = list(map(int, input().split()))

    if day <= M:

        jobs[day].append(value)



ans = 0

hq = []

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

    for value in jobs[day]:

        heapq.heappush(hq, - value)

    if len(hq) > 0:

        ans -= heapq.heappop(hq)



print(ans)

import heapq

import sys

from collections import defaultdict



input = sys.stdin.readline

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

jobs = defaultdict(list)

for _ in range(N):

    day, value = list(map(int, input().split()))

    if day <= M:

        jobs[day].append(value)



ans = 0

hq = []

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

    for value in jobs[day]:

        heapq.heappush(hq, - value)

    if len(hq) > 0:

        ans -= heapq.heappop(hq)



print(ans)

import heapq

N, M = list(map(int, input().split()))
jobs = [[] for _ in range(M + 1)]
for _ in range(N):
    day, value = list(map(int, input().split()))
    if day <= M:
        jobs[day].append(value)
ans = 0
hq = []
for day in range(1, M + 1):
    for value in jobs[day]:
        heapq.heappush(hq, -value)
    if len(hq) > 0:
        ans -= heapq.heappop(hq)
print(ans)

import heapq
import sys
from collections import defaultdict

input = sys.stdin.readline
N, M = list(map(int, input().split()))
jobs = defaultdict(list)
for _ in range(N):
    day, value = list(map(int, input().split()))
    if day <= M:
        jobs[day].append(value)
ans = 0
hq = []
for day in range(1, M + 1):
    for value in jobs[day]:
        heapq.heappush(hq, -value)
    if len(hq) > 0:
        ans -= heapq.heappop(hq)
print(ans)

+import sys +from collections import defaultdict +input = sys.stdin.readline -jobs = [[] for _ in range(M + 1)] +jobs = defaultdict(list)