# D - Summer Vacation

from heapq import *

from collections import defaultdict



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

jobs = defaultdict(list)

for _ in range(n):

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

    jobs[a].append(-b)



result = 0

pool = []

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

    for j in jobs[i]:

        heappush(pool, j)

    if 0 < len(pool):

        result += -heappop(pool)



print(result)
import sys

from heapq import heappop, heappush



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, M = lr()

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

# M-1日後から選んでいく,

for _ in range(N):

    a, b = lr()

    if a > M:

        continue

    works[a].append(-b)



heap = []

answer = 0

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

    for x in works[i]:

        heappush(heap, x)

    if len(heap) == 0:

        continue

    answer += heappop(heap)



answer *= -1

print(answer)

# 08
# D - Summer Vacation
from heapq import *
from collections import defaultdict

n, m = list(map(int, input().split()))
jobs = defaultdict(list)
for _ in range(n):
    a, b = list(map(int, input().split()))
    jobs[a].append(-b)
result = 0
pool = []
for i in range(1, m + 1):
    for j in jobs[i]:
        heappush(pool, j)
    if 0 < len(pool):
        result += -heappop(pool)
print(result)

import sys
from heapq import heappop, heappush

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
works = [[] for _ in range(M + 1)]
# M-1日後から選んでいく,
for _ in range(N):
    a, b = lr()
    if a > M:
        continue
    works[a].append(-b)
heap = []
answer = 0
for i in range(1, M + 1):
    for x in works[i]:
        heappush(heap, x)
    if len(heap) == 0:
        continue
    answer += heappop(heap)
answer *= -1
print(answer)
# 08

-# D - Summer Vacation -from heapq import * -from collections import defaultdict +import sys +from heapq import heappop, heappush -n, m = list(map(int, input().split())) -jobs = defaultdict(list) -for _ in range(n): -    a, b = list(map(int, input().split())) -    jobs[a].append(-b) -result = 0 -pool = [] -for i in range(1, m + 1): -    for j in jobs[i]: -        heappush(pool, j) -    if 0 < len(pool): -        result += -heappop(pool) -print(result) +sr = lambda: sys.stdin.readline().rstrip() +ir = lambda: int(sr()) +lr = lambda: list(map(int, sr().split())) +N, M = lr() +works = [[] for _ in range(M + 1)] +# M-1日後から選んでいく, +for _ in range(N): +    a, b = lr() +    if a > M: +        continue +    works[a].append(-b) +heap = [] +answer = 0 +for i in range(1, M + 1): +    for x in works[i]: +        heappush(heap, x) +    if len(heap) == 0: +        continue +    answer += heappop(heap) +answer *= -1 +print(answer) +# 08