import sys

readline = sys.stdin.readline



# 逆順に見ていく

# A_iの値が小さい順にheapqに追加していく



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

from collections import defaultdict

tasks = defaultdict(list)

for i in range(N):

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

  tasks[a].append(b)

  

import heapq

q = []

heapq.heapify(q)

ans = 0

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

  for task in tasks[i]:

    heapq.heappush(q,-task)

  if q:

    t = heapq.heappop(q)

    ans += (-t)



print(ans)
import sys

readline = sys.stdin.readline



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

from collections import defaultdict

tasks = defaultdict(list)

for i in range(N):

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

  tasks[a].append(b)

  

import heapq as hq

q = []

ans = 0

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

  newtask = tasks[i]

  for t in newtask:

    hq.heappush(q,-t)

  if q:

    ans += -hq.heappop(q)



print(ans)
import sys

readline = sys.stdin.readline
# 逆順に見ていく
# A_iの値が小さい順にheapqに追加していく
N, M = list(map(int, readline().split()))
from collections import defaultdict

tasks = defaultdict(list)
for i in range(N):
    a, b = list(map(int, readline().split()))
    tasks[a].append(b)
import heapq

q = []
heapq.heapify(q)
ans = 0
for i in range(1, M + 1):
    for task in tasks[i]:
        heapq.heappush(q, -task)
    if q:
        t = heapq.heappop(q)
        ans += -t
print(ans)

import sys

readline = sys.stdin.readline
N, M = list(map(int, readline().split()))
from collections import defaultdict

tasks = defaultdict(list)
for i in range(N):
    a, b = list(map(int, readline().split()))
    tasks[a].append(b)
import heapq as hq

q = []
ans = 0
for i in range(1, M + 1):
    newtask = tasks[i]
    for t in newtask:
        hq.heappush(q, -t)
    if q:
        ans += -hq.heappop(q)
print(ans)

-# 逆順に見ていく -# A_iの値が小さい順にheapqに追加していく -import heapq +import heapq as hq -heapq.heapify(q) -    for task in tasks[i]: -        heapq.heappush(q, -task) +    newtask = tasks[i] +    for t in newtask: +        hq.heappush(q, -t) -        t = heapq.heappop(q) -        ans += -t +        ans += -hq.heappop(q)