import sys

import heapq





def solve():

    input = sys.stdin.readline

    mod = 10 ** 9 + 7

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

    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]

    ab.sort(reverse=True)

    ls = []

    heapq.heapify(ls)

    t = 0

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

        while True:

            if len(ab) != 0:

                if ab[-1][0] <= i:

                    heapq.heappush(ls, -ab.pop()[1])

                else:

                    break

            else:

                break

        if len(ls) != 0:

            t -= heapq.heappop(ls)

    print(t)





if __name__ == '__main__':

    solve()

import sys

import collections

import heapq





def solve():

    readline = sys.stdin.buffer.readline

    mod = 10 ** 9 + 7

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

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

    ab.sort()

    ab = collections.deque(ab)

    hq = []

    heapq.heapify(hq)

    t = 0

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

        while len(ab):

            if len(ab) != 0:

                if ab[0][0] <= i:

                    heapq.heappush(hq, -ab.popleft()[1])

                else:

                    break

            else:

                break

        if len(hq) != 0:

            t -= heapq.heappop(hq)

    print(t)





if __name__ == '__main__':

    solve()

import sys
import heapq


def solve():
    input = sys.stdin.readline
    mod = 10**9 + 7
    n, m = list(map(int, input().rstrip("\n").split()))
    ab = [list(map(int, input().rstrip("\n").split())) for _ in range(n)]
    ab.sort(reverse=True)
    ls = []
    heapq.heapify(ls)
    t = 0
    for i in range(1, m + 1):
        while True:
            if len(ab) != 0:
                if ab[-1][0] <= i:
                    heapq.heappush(ls, -ab.pop()[1])
                else:
                    break
            else:
                break
        if len(ls) != 0:
            t -= heapq.heappop(ls)
    print(t)


if __name__ == "__main__":
    solve()

import sys
import collections
import heapq


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10**9 + 7
    n, m = list(map(int, readline().split()))
    ab = [list(map(int, readline().split())) for _ in range(n)]
    ab.sort()
    ab = collections.deque(ab)
    hq = []
    heapq.heapify(hq)
    t = 0
    for i in range(1, m + 1):
        while len(ab):
            if len(ab) != 0:
                if ab[0][0] <= i:
                    heapq.heappush(hq, -ab.popleft()[1])
                else:
                    break
            else:
                break
        if len(hq) != 0:
            t -= heapq.heappop(hq)
    print(t)


if __name__ == "__main__":
    solve()

+import collections -    input = sys.stdin.readline +    readline = sys.stdin.buffer.readline -    n, m = list(map(int, input().rstrip("\n").split())) -    ab = [list(map(int, input().rstrip("\n").split())) for _ in range(n)] -    ab.sort(reverse=True) -    ls = [] -    heapq.heapify(ls) +    n, m = list(map(int, readline().split())) +    ab = [list(map(int, readline().split())) for _ in range(n)] +    ab.sort() +    ab = collections.deque(ab) +    hq = [] +    heapq.heapify(hq) -        while True: +        while len(ab): -                if ab[-1][0] <= i: -                    heapq.heappush(ls, -ab.pop()[1]) +                if ab[0][0] <= i: +                    heapq.heappush(hq, -ab.popleft()[1]) -        if len(ls) != 0: -            t -= heapq.heappop(ls) +        if len(hq) != 0: +            t -= heapq.heappop(hq)