def slove():

    import sys, heapq

    input = sys.stdin.readline

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

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

    heapq.heapify(ab)

    s_q = []

    heapq.heapify(s_q)

    r = 0

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

        while True:

            if len(ab) != 0:

                p = heapq.heappop(ab)

                if p[0] <= d:

                    heapq.heappush(s_q, -p[1])

                else:

                    heapq.heappush(ab, p)

                    break

            else:

                break

        if len(s_q) != 0:

            mr = -heapq.heappop(s_q)

            r += mr

        d -= 1

    print(r)





if __name__ == '__main__':

    slove()

def slove():

    import sys

    import heapq

    input = sys.stdin.readline

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

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

    r = []

    heapq.heapify(l)

    heapq.heapify(r)

    t = 0

    for i in range(m + 1):

        while True:

            if len(l) != 0:

                a, b = heapq.heappop(l)

                if a <= i:

                    heapq.heappush(r, -b)

                else:

                    heapq.heappush(l, [a, b])

                    break

            else:

                break

        if len(r) != 0:

            t += -heapq.heappop(r)

    print(t)





if __name__ == '__main__':

    slove()

def slove():
    import sys, heapq

    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip("\n").split()))
    ab = [list(map(int, input().rstrip("\n").split())) for _ in range(n)]
    heapq.heapify(ab)
    s_q = []
    heapq.heapify(s_q)
    r = 0
    for d in range(1, m + 1):
        while True:
            if len(ab) != 0:
                p = heapq.heappop(ab)
                if p[0] <= d:
                    heapq.heappush(s_q, -p[1])
                else:
                    heapq.heappush(ab, p)
                    break
            else:
                break
        if len(s_q) != 0:
            mr = -heapq.heappop(s_q)
            r += mr
        d -= 1
    print(r)


if __name__ == "__main__":
    slove()

def slove():
    import sys
    import heapq

    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip("\n").split()))
    l = [list(map(int, input().rstrip("\n").split())) for _ in range(n)]
    r = []
    heapq.heapify(l)
    heapq.heapify(r)
    t = 0
    for i in range(m + 1):
        while True:
            if len(l) != 0:
                a, b = heapq.heappop(l)
                if a <= i:
                    heapq.heappush(r, -b)
                else:
                    heapq.heappush(l, [a, b])
                    break
            else:
                break
        if len(r) != 0:
            t += -heapq.heappop(r)
    print(t)


if __name__ == "__main__":
    slove()

-    import sys, heapq +    import sys +    import heapq -    ab = [list(map(int, input().rstrip("\n").split())) for _ in range(n)] -    heapq.heapify(ab) -    s_q = [] -    heapq.heapify(s_q) -    r = 0 -    for d in range(1, m + 1): +    l = [list(map(int, input().rstrip("\n").split())) for _ in range(n)] +    r = [] +    heapq.heapify(l) +    heapq.heapify(r) +    t = 0 +    for i in range(m + 1): -            if len(ab) != 0: -                p = heapq.heappop(ab) -                if p[0] <= d: -                    heapq.heappush(s_q, -p[1]) +            if len(l) != 0: +                a, b = heapq.heappop(l) +                if a <= i: +                    heapq.heappush(r, -b) -                    heapq.heappush(ab, p) +                    heapq.heappush(l, [a, b]) -        if len(s_q) != 0: -            mr = -heapq.heappop(s_q) -            r += mr -        d -= 1 -    print(r) +        if len(r) != 0: +            t += -heapq.heappop(r) +    print(t)