### BUGGY CODE ###

from collections import defaultdict, deque
import sys
import math

sys.setrecursionlimit(100000)

MIN = -10 ** 9
MAX = 10 ** 9 + 7


def merge(a, b, m):
    # return sorted(a+b)[-m:]
    m = min(m, len(a) + len(b))
    res = [0] * m
    if len(a) == 0:
        return b
    if len(b) == 0:
        return a
    ia = len(a) - 1
    ib = len(b) - 1
    for i in range(m):
        j = m - 1 - i
        if ia < 0:
            res[j] = b[ib]
            ib -= 1
            continue
        if ib < 0:
            res[j] = a[ia]
            ia -= 1
            continue
        if a[ia] > b[ib]:
            res[j] = a[ia]
            ia -= 1
            # if ia < 0:
            #     return b[:m - j] + res[j:]
                # while True:
                #     j -= 1
                #     if j < 0:
                #         break
                #     res[j] = b[ib]
                #     ib -= 1
                # return res
        else:
            res[j] = b[ib]
            ib -= 1
            # if ib < 0:
            #     return a[:m - j] + res[j:]
                # while True:
                #     if j < 0:
                #         break
                #     res[j] = a[ia]
                #     ia -= 1
                # return res
    return res


# print(merge([1], [1, 2, 3], 3))
# print(merge([1], [1, 2, 3], 1))
# print(merge([1], [1, 2, 3], 5))


def main():
    # N = int(input())
    N, M = [int(a) for a in input().split()]
    AB = [
        [int(a) for a in input().split()]
        for _ in range(N)
    ]

    AB = sorted(AB, key=lambda it: it[1])

    ARR = [[] for _ in range(M + 1)]
    for a, b in AB:
        if a > M:
            continue
        ARR[a].append(b)
    # print("ARR", ARR)

    res = 0
    q = []

    for i in range(1, M + 1):
        current = ARR[i]
        if len(current) != 0:
            if len(q) != 0:
                if current[-1] > q[-1]:
                    res += current.pop()
                else:
                    res += q.pop()
            else:
                res += current.pop()
            q = merge(q, current, M - i)
        else:
            if len(q) != 0:
                res += q.pop()
            else:
                pass
        # q += current
        # q = sorted(q)
        # # print(q)
        # if len(q) != 0:
        #     mm = q.pop()
        #     res += mm
        # q = q[-(M - i):]
    print(res)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import defaultdict, deque
import sys
import heapq
import math

sys.setrecursionlimit(100000)

MIN = -10 ** 9
MAX = 10 ** 9 + 7


def main():
    # N = int(input())
    N, M = [int(a) for a in input().split()]
    AB = [
        [int(a) for a in input().split()]
        for _ in range(N)
    ]

    # AB = sorted(AB, key=lambda it: it[1])

    ARR = [[] for _ in range(M + 1)]
    for a, b in AB:
        if a > M:
            continue
        ARR[a].append(b)
    # print("ARR", ARR)

    res = 0
    q = []
    for i in range(1, M + 1):
        current = ARR[i]
        for a in current:
            heapq.heappush(q, -a)
        if len(q) != 0:
            res -= heapq.heappop(q)
    print(res)


if __name__ == '__main__':
    main()