# ABC137D - Summer Vacation

import sys

from heapq import heappop, heappush



readline = sys.stdin.buffer.readline

heappop_max = lambda heap: -heappop(heap)

heappush_max = lambda heap, x: heappush(heap, -x)





def main():

    N, M = list(map(int, readline().split()))

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

    for _ in range(N):

        waiting_days, reward = list(map(int, readline().split()))

        if waiting_days <= M:

            available_jobs[waiting_days].append(reward)

    heap = []

    max_rewards = 0

    for jobs in available_jobs[1:]:

        for job in jobs:

            heappush_max(heap, job)

        if heap:

            max_rewards += heappop_max(heap)

    print(max_rewards)





if __name__ == "__main__":

    main()

# ABC137D - Summer Vacation

import sys

from heapq import heappop, heappush



read = sys.stdin.buffer.read

heappop_max = lambda heap: -heappop(heap)

heappush_max = lambda heap, x: heappush(heap, -x)





def main():

    N, M, *all_jobs = list(map(int, read().split()))

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

    for waiting_days, reward in zip(*[iter(all_jobs)] * 2):

        if waiting_days <= M:

            available_jobs[waiting_days].append(reward)

    heap = []

    max_rewards = 0

    for jobs in available_jobs[1:]:

        for job in jobs:

            heappush_max(heap, job)

        if heap:

            max_rewards += heappop_max(heap)

    print(max_rewards)





if __name__ == "__main__":

    main()

# ABC137D - Summer Vacation
import sys
from heapq import heappop, heappush

readline = sys.stdin.buffer.readline
heappop_max = lambda heap: -heappop(heap)
heappush_max = lambda heap, x: heappush(heap, -x)


def main():
    N, M = list(map(int, readline().split()))
    available_jobs = [[] for _ in range(M + 1)]
    for _ in range(N):
        waiting_days, reward = list(map(int, readline().split()))
        if waiting_days <= M:
            available_jobs[waiting_days].append(reward)
    heap = []
    max_rewards = 0
    for jobs in available_jobs[1:]:
        for job in jobs:
            heappush_max(heap, job)
        if heap:
            max_rewards += heappop_max(heap)
    print(max_rewards)


if __name__ == "__main__":
    main()

# ABC137D - Summer Vacation
import sys
from heapq import heappop, heappush

read = sys.stdin.buffer.read
heappop_max = lambda heap: -heappop(heap)
heappush_max = lambda heap, x: heappush(heap, -x)


def main():
    N, M, *all_jobs = list(map(int, read().split()))
    available_jobs = [[] for _ in range(M + 1)]
    for waiting_days, reward in zip(*[iter(all_jobs)] * 2):
        if waiting_days <= M:
            available_jobs[waiting_days].append(reward)
    heap = []
    max_rewards = 0
    for jobs in available_jobs[1:]:
        for job in jobs:
            heappush_max(heap, job)
        if heap:
            max_rewards += heappop_max(heap)
    print(max_rewards)


if __name__ == "__main__":
    main()

-readline = sys.stdin.buffer.readline +read = sys.stdin.buffer.read -    N, M = list(map(int, readline().split())) +    N, M, *all_jobs = list(map(int, read().split())) -    for _ in range(N): -        waiting_days, reward = list(map(int, readline().split())) +    for waiting_days, reward in zip(*[iter(all_jobs)] * 2):