import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

from collections import deque



sys.setrecursionlimit(10**7)

inf = 10**20

mod = 10**9 + 7



DR = [1, -1, 0, 0]

DC = [0, 0, 1, -1]



def LI(): return [int(x) for x in sys.stdin.readline().split()]

def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]

def LF(): return [float(x) for x in sys.stdin.readline().split()]

def LS(): return sys.stdin.readline().split()

def I(): return int(sys.stdin.readline())

def F(): return float(sys.stdin.readline())

def S(): return eval(input())



def _heappush_max(heap, item):

    heap.append(item)

    heapq._siftdown_max(heap, 0, len(heap)-1)

def _heappop_max(heap):

    """Maxheap version of a heappop."""

    lastelt = heap.pop()    # raises appropriate IndexError if heap is empty

    if heap:

        returnitem = heap[0]

        heap[0] = lastelt

        heapq._siftup_max(heap, 0)

        return returnitem

    return lastelt



def main():

    N, M = LI()

    jobsavailable = [[] for _ in range(10**5+1)]

    for _ in range(N):

        a, b = LI()

        if a > M:

            continue

        jobsavailable[M-a].append(b)

    cur_jobs = []

    cnt = 0

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

        # a <= iのなかで最大のbがあるものをとりだす

        jobs = jobsavailable[M-i]

        for j in jobs:

            _heappush_max(cur_jobs, j)

        if cur_jobs != []:

            j = _heappop_max(cur_jobs)

            cnt += j

    print(cnt)



main()



import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

from collections import deque



sys.setrecursionlimit(10**7)

inf = 10**20

mod = 10**9 + 7



DR = [1, -1, 0, 0]

DC = [0, 0, 1, -1]



def LI(): return [int(x) for x in sys.stdin.readline().split()]

def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]

def LF(): return [float(x) for x in sys.stdin.readline().split()]

def LS(): return sys.stdin.readline().split()

def I(): return int(sys.stdin.readline())

def F(): return float(sys.stdin.readline())

def S(): return eval(input())



def main():

    N, M = LI()

    jobsavailable = [[] for _ in range(10**5+1)]

    for _ in range(N):

        a, b = LI()

        if a > M:

            continue

        jobsavailable[M-a].append(b)

    cur_jobs = []

    cnt = 0

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

        jobs = jobsavailable[M-i]

        for j in jobs:

            heapq.heappush(cur_jobs, -j)

        if cur_jobs != []:

            j = -heapq.heappop(cur_jobs)

            cnt += j

    print(cnt)



main()



import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]


def LI():
    return [int(x) for x in sys.stdin.readline().split()]


def LI_():
    return [int(x) - 1 for x in sys.stdin.readline().split()]


def LF():
    return [float(x) for x in sys.stdin.readline().split()]


def LS():
    return sys.stdin.readline().split()


def I():
    return int(sys.stdin.readline())


def F():
    return float(sys.stdin.readline())


def S():
    return eval(input())


def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap) - 1)


def _heappop_max(heap):
    """Maxheap version of a heappop."""
    lastelt = heap.pop()  # raises appropriate IndexError if heap is empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt


def main():
    N, M = LI()
    jobsavailable = [[] for _ in range(10**5 + 1)]
    for _ in range(N):
        a, b = LI()
        if a > M:
            continue
        jobsavailable[M - a].append(b)
    cur_jobs = []
    cnt = 0
    for i in range(1, M + 1):
        # a <= iのなかで最大のbがあるものをとりだす
        jobs = jobsavailable[M - i]
        for j in jobs:
            _heappush_max(cur_jobs, j)
        if cur_jobs != []:
            j = _heappop_max(cur_jobs)
            cnt += j
    print(cnt)


main()

import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]


def LI():
    return [int(x) for x in sys.stdin.readline().split()]


def LI_():
    return [int(x) - 1 for x in sys.stdin.readline().split()]


def LF():
    return [float(x) for x in sys.stdin.readline().split()]


def LS():
    return sys.stdin.readline().split()


def I():
    return int(sys.stdin.readline())


def F():
    return float(sys.stdin.readline())


def S():
    return eval(input())


def main():
    N, M = LI()
    jobsavailable = [[] for _ in range(10**5 + 1)]
    for _ in range(N):
        a, b = LI()
        if a > M:
            continue
        jobsavailable[M - a].append(b)
    cur_jobs = []
    cnt = 0
    for i in range(1, M + 1):
        jobs = jobsavailable[M - i]
        for j in jobs:
            heapq.heappush(cur_jobs, -j)
        if cur_jobs != []:
            j = -heapq.heappop(cur_jobs)
            cnt += j
    print(cnt)


main()

-def _heappush_max(heap, item): -    heap.append(item) -    heapq._siftdown_max(heap, 0, len(heap) - 1) - - -def _heappop_max(heap): -    """Maxheap version of a heappop.""" -    lastelt = heap.pop()  # raises appropriate IndexError if heap is empty -    if heap: -        returnitem = heap[0] -        heap[0] = lastelt -        heapq._siftup_max(heap, 0) -        return returnitem -    return lastelt - - -        # a <= iのなかで最大のbがあるものをとりだす -            _heappush_max(cur_jobs, j) +            heapq.heappush(cur_jobs, -j) -            j = _heappop_max(cur_jobs) +            j = -heapq.heappop(cur_jobs)