import sys

input = sys.stdin.readline

import heapq



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

jobs = [[] for i in range(m)]

for i in range(n):

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

    if a > m:

        pass

    else:

        jobs[m - a].append(b)



if len(jobs) == 0:

    print((0))

    exit(0)



q = []

heapq.heapify(q)

ans = 0

for i in reversed(list(range(m))):

    for b in jobs[i]:

        heapq.heappush(q, -b)

    if len(q) != 0:

        ans += heapq.heappop(q) * -1



print(ans)

import sys

from heapq import heappush, heappop



sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline

f_inf = float('inf')

mod = 10 ** 9 + 7





def resolve():

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

    AB = [[] for _ in range(m)]

    for _ in range(n):

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

        if a <= m:

            AB[m - a].append(b)



    que = []

    res = 0

    for i in reversed(list(range(m))):

        for b in AB[i]:

            heappush(que, -b)

        if que:

            res += heappop(que) * -1

    print(res)





if __name__ == '__main__':

    resolve()

import sys

input = sys.stdin.readline
import heapq

n, m = list(map(int, input().split()))
jobs = [[] for i in range(m)]
for i in range(n):
    a, b = list(map(int, input().split()))
    if a > m:
        pass
    else:
        jobs[m - a].append(b)
if len(jobs) == 0:
    print((0))
    exit(0)
q = []
heapq.heapify(q)
ans = 0
for i in reversed(list(range(m))):
    for b in jobs[i]:
        heapq.heappush(q, -b)
    if len(q) != 0:
        ans += heapq.heappop(q) * -1
print(ans)

import sys
from heapq import heappush, heappop

sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7


def resolve():
    n, m = list(map(int, input().split()))
    AB = [[] for _ in range(m)]
    for _ in range(n):
        a, b = list(map(int, input().split()))
        if a <= m:
            AB[m - a].append(b)
    que = []
    res = 0
    for i in reversed(list(range(m))):
        for b in AB[i]:
            heappush(que, -b)
        if que:
            res += heappop(que) * -1
    print(res)


if __name__ == "__main__":
    resolve()

+from heapq import heappush, heappop +sys.setrecursionlimit(10**7) -import heapq +f_inf = float("inf") +mod = 10**9 + 7 -n, m = list(map(int, input().split())) -jobs = [[] for i in range(m)] -for i in range(n): -    a, b = list(map(int, input().split())) -    if a > m: -        pass -    else: -        jobs[m - a].append(b) -if len(jobs) == 0: -    print((0)) -    exit(0) -q = [] -heapq.heapify(q) -ans = 0 -for i in reversed(list(range(m))): -    for b in jobs[i]: -        heapq.heappush(q, -b) -    if len(q) != 0: -        ans += heapq.heappop(q) * -1 -print(ans) + +def resolve(): +    n, m = list(map(int, input().split())) +    AB = [[] for _ in range(m)] +    for _ in range(n): +        a, b = list(map(int, input().split())) +        if a <= m: +            AB[m - a].append(b) +    que = [] +    res = 0 +    for i in reversed(list(range(m))): +        for b in AB[i]: +            heappush(que, -b) +        if que: +            res += heappop(que) * -1 +    print(res) + + +if __name__ == "__main__": +    resolve()