import heapq



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

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

arr2=[[i,0] for i in range(1,m+2)]

arr.extend(arr2)

arr=sorted(arr,reverse=True,key=lambda x:x[1])

arr=sorted(arr,key=lambda x:x[0])

q=[]

ans=0

pos=0

while 1:

  a,b=arr[pos]

  if a>m:

    break

  if a==arr[pos+1][0]:

    heapq.heappush(q,-b)

  else:

    heapq.heappush(q,-b)

    ans-=heapq.heappop(q)

  pos+=1

print(ans)
import heapq



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

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

arr2=[[i,0] for i in range(1,m+2)]

arr.extend(arr2)

arr=sorted(arr,key=lambda x:x[0])

q=[]

ans=0

pos=0

while 1:

  a,b=arr[pos]

  if a>m:

    break

  if a==arr[pos+1][0]:

    heapq.heappush(q,-b)

  else:

    heapq.heappush(q,-b)

    ans-=heapq.heappop(q)

  pos+=1

print(ans)
import heapq

n, m = list(map(int, input().split()))
arr = [list(map(int, input().split())) for _ in range(n)]
arr2 = [[i, 0] for i in range(1, m + 2)]
arr.extend(arr2)
arr = sorted(arr, reverse=True, key=lambda x: x[1])
arr = sorted(arr, key=lambda x: x[0])
q = []
ans = 0
pos = 0
while 1:
    a, b = arr[pos]
    if a > m:
        break
    if a == arr[pos + 1][0]:
        heapq.heappush(q, -b)
    else:
        heapq.heappush(q, -b)
        ans -= heapq.heappop(q)
    pos += 1
print(ans)

import heapq

n, m = list(map(int, input().split()))
arr = [list(map(int, input().split())) for _ in range(n)]
arr2 = [[i, 0] for i in range(1, m + 2)]
arr.extend(arr2)
arr = sorted(arr, key=lambda x: x[0])
q = []
ans = 0
pos = 0
while 1:
    a, b = arr[pos]
    if a > m:
        break
    if a == arr[pos + 1][0]:
        heapq.heappush(q, -b)
    else:
        heapq.heappush(q, -b)
        ans -= heapq.heappop(q)
    pos += 1
print(ans)

-arr = sorted(arr, reverse=True, key=lambda x: x[1])