import heapq

from collections import deque



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

AB=[list(map(int, input().split())) for _ in range(N)]

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

for i in range(N):

  AB[i][1]=-AB[i][1]

d=deque(AB)

ans=0

h=[]

for i in range(M+1):

  if not d and not h:

    break

  while d and d[0][0]<=i:

    heapq.heappush(h, d.popleft()[1])

  if h:

    ans-=heapq.heappop(h)

print(ans)
import heapq

from collections import deque



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

AB=[list(map(int,input().split())) for _ in range(N)]

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

d=deque(AB)

h=[]

ans=0

for i in range(M+1):

    while d and d[0][0]<=i:

        heapq.heappush(h, -d.popleft()[1])

    if h:

        ans-=heapq.heappop(h)

print(ans)
import heapq
from collections import deque

N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: (x[0], x[1]))
for i in range(N):
    AB[i][1] = -AB[i][1]
d = deque(AB)
ans = 0
h = []
for i in range(M + 1):
    if not d and not h:
        break
    while d and d[0][0] <= i:
        heapq.heappush(h, d.popleft()[1])
    if h:
        ans -= heapq.heappop(h)
print(ans)

import heapq
from collections import deque

N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[0])
d = deque(AB)
h = []
ans = 0
for i in range(M + 1):
    while d and d[0][0] <= i:
        heapq.heappush(h, -d.popleft()[1])
    if h:
        ans -= heapq.heappop(h)
print(ans)

-AB.sort(key=lambda x: (x[0], x[1])) -for i in range(N): -    AB[i][1] = -AB[i][1] +AB.sort(key=lambda x: x[0]) +h = [] -h = [] -    if not d and not h: -        break -        heapq.heappush(h, d.popleft()[1]) +        heapq.heappush(h, -d.popleft()[1])