from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,fractions,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))



n,m = inpl()

ab = [inpl() for i in range(n)]

hq = []

res = 0

ind = 0

ab.sort()

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

    while True:

        if ind >= n: break

        a,b = ab[ind]

        if a <= i:

            heappush(hq,[-b,a])

            ind += 1

        else: break

    if hq == []: continue

    tmp = heappop(hq)

    res -= tmp[0]

    # print(tmp,res)

print(res)
from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,fractions,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))



n,m = inpl()

jobs = [inpl() for _ in range(n)]

jobs.sort()

can = []

ind = 0

res = 0

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

    while ind < n:

        a,b = jobs[ind]

        if a == i:

            heappush(can,-b)

            ind += 1

            continue

        break

    if can != []:

        res -= heappop(can)

print(res)
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


n, m = inpl()
ab = [inpl() for i in range(n)]
hq = []
res = 0
ind = 0
ab.sort()
for i in range(1, m + 1):
    while True:
        if ind >= n:
            break
        a, b = ab[ind]
        if a <= i:
            heappush(hq, [-b, a])
            ind += 1
        else:
            break
    if hq == []:
        continue
    tmp = heappop(hq)
    res -= tmp[0]
    # print(tmp,res)
print(res)

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


n, m = inpl()
jobs = [inpl() for _ in range(n)]
jobs.sort()
can = []
ind = 0
res = 0
for i in range(1, m + 1):
    while ind < n:
        a, b = jobs[ind]
        if a == i:
            heappush(can, -b)
            ind += 1
            continue
        break
    if can != []:
        res -= heappop(can)
print(res)

-ab = [inpl() for i in range(n)] -hq = [] +jobs = [inpl() for _ in range(n)] +jobs.sort() +can = [] +ind = 0 -ind = 0 -ab.sort() -    while True: -        if ind >= n: -            break -        a, b = ab[ind] -        if a <= i: -            heappush(hq, [-b, a]) +    while ind < n: +        a, b = jobs[ind] +        if a == i: +            heappush(can, -b) -        else: -            break -    if hq == []: -        continue -    tmp = heappop(hq) -    res -= tmp[0] -    # print(tmp,res) +            continue +        break +    if can != []: +        res -= heappop(can)