# ABC137D - Summer Vacation

import sys

input = sys.stdin.readline



from heapq import heappush, heappushpop





def main():

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

    T = [[] for _ in range(M + 1)]

    for _ in range(N):

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

        if a <= M:

            T[M - a] += [b]

    q = []

    for i in range(M + 1):

        for v in T[i]:

            if len(q) <= i:

                heappush(q, v)

            else:

                heappushpop(q, v)

    print((sum(q)))





if __name__ == "__main__":

    main()
# ABC137D - Summer Vacation

from heapq import heappush, heappushpop





def main():

    N, M, *A = list(map(int, open(0).read().split()))

    # T[i] := candidates of values on i-th deadline

    T = [[] for _ in range(M + 1)]

    for a, b in zip(*[iter(A)] * 2):

        if a <= M:

            T[M - a] += [b]

    q = []  # heapq

    for i in range(M + 1):

        for v in T[i]:

            # keep i worthwhile tasks in i-th day

            if len(q) <= i:

                heappush(q, v)

            else:

                heappushpop(q, v)

    print((sum(q)))





if __name__ == "__main__":

    main()
# ABC137D - Summer Vacation
import sys

input = sys.stdin.readline
from heapq import heappush, heappushpop


def main():
    N, M = tuple(map(int, input().split()))
    T = [[] for _ in range(M + 1)]
    for _ in range(N):
        a, b = list(map(int, input().rstrip().split()))
        if a <= M:
            T[M - a] += [b]
    q = []
    for i in range(M + 1):
        for v in T[i]:
            if len(q) <= i:
                heappush(q, v)
            else:
                heappushpop(q, v)
    print((sum(q)))


if __name__ == "__main__":
    main()

# ABC137D - Summer Vacation
from heapq import heappush, heappushpop


def main():
    N, M, *A = list(map(int, open(0).read().split()))
    # T[i] := candidates of values on i-th deadline
    T = [[] for _ in range(M + 1)]
    for a, b in zip(*[iter(A)] * 2):
        if a <= M:
            T[M - a] += [b]
    q = []  # heapq
    for i in range(M + 1):
        for v in T[i]:
            # keep i worthwhile tasks in i-th day
            if len(q) <= i:
                heappush(q, v)
            else:
                heappushpop(q, v)
    print((sum(q)))


if __name__ == "__main__":
    main()

-import sys - -input = sys.stdin.readline -    N, M = tuple(map(int, input().split())) +    N, M, *A = list(map(int, open(0).read().split())) +    # T[i] := candidates of values on i-th deadline -    for _ in range(N): -        a, b = list(map(int, input().rstrip().split())) +    for a, b in zip(*[iter(A)] * 2): -    q = [] +    q = []  # heapq +            # keep i worthwhile tasks in i-th day