import heapq

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

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



AB.sort(reverse=True)

works=[]

heapq.heapify(works)

ans=0

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

  day=M-i

  latest=i

  while AB and AB[-1][0]<=latest:

    a,b=AB.pop(-1)

    heapq.heappush(works,-b)

  if not works:

    continue

  ans-=heapq.heappop(works)



print(ans)

import heapq

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

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



AB.sort(reverse=True)

works=[]

heapq.heapify(works)

ans=0

AB=AB+[[0,0]]

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

  day=M-i

  latest=i

  while len(AB)>=2 and AB[-2][0]<=latest:

    a,b=AB.pop(-2)

    heapq.heappush(works,-b)

  if not works:

    continue

  ans-=heapq.heappop(works)



print(ans)

import heapq

N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(reverse=True)
works = []
heapq.heapify(works)
ans = 0
for i in range(1, M + 1):
    day = M - i
    latest = i
    while AB and AB[-1][0] <= latest:
        a, b = AB.pop(-1)
        heapq.heappush(works, -b)
    if not works:
        continue
    ans -= heapq.heappop(works)
print(ans)

import heapq

N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(reverse=True)
works = []
heapq.heapify(works)
ans = 0
AB = AB + [[0, 0]]
for i in range(1, M + 1):
    day = M - i
    latest = i
    while len(AB) >= 2 and AB[-2][0] <= latest:
        a, b = AB.pop(-2)
        heapq.heappush(works, -b)
    if not works:
        continue
    ans -= heapq.heappop(works)
print(ans)

+AB = AB + [[0, 0]] -    while AB and AB[-1][0] <= latest: -        a, b = AB.pop(-1) +    while len(AB) >= 2 and AB[-2][0] <= latest: +        a, b = AB.pop(-2)