import sys


def input():
    return sys.stdin.readline()[:-1]


N, M = map(int, input().split())
l = [[] for i in range(10 ** 5)]
for i in range(N):
    a, b = map(int, input().split())
    l[a - 1].append(b)
h = []
import heapq
a = 0
for i in range(M):
    for j in l[i]:
        heapq.heappush(h, -j)
    if h:
        a -= heapq.heappop(h)
print(a)

f7b257db1ef1c5f7e7134ab0f230a584ec0948c6
<mask token>


def input():
    return sys.stdin.readline()[:-1]


<mask token>

<mask token>


def input():
    return sys.stdin.readline()[:-1]


<mask token>
for i in range(N):
    a, b = map(int, input().split())
    l[a - 1].append(b)
<mask token>
for i in range(M):
    for j in l[i]:
        heapq.heappush(h, -j)
    if h:
        a -= heapq.heappop(h)
print(a)

<mask token>


def input():
    return sys.stdin.readline()[:-1]


N, M = map(int, input().split())
l = [[] for i in range(10 ** 5)]
for i in range(N):
    a, b = map(int, input().split())
    l[a - 1].append(b)
h = []
<mask token>
a = 0
for i in range(M):
    for j in l[i]:
        heapq.heappush(h, -j)
    if h:
        a -= heapq.heappop(h)
print(a)

import sys


def input():
    return sys.stdin.readline()[:-1]


N, M = map(int, input().split())
l = [[] for i in range(10 ** 5)]
for i in range(N):
    a, b = map(int, input().split())
    l[a - 1].append(b)
h = []
import heapq
a = 0
for i in range(M):
    for j in l[i]:
        heapq.heappush(h, -j)
    if h:
        a -= heapq.heappop(h)
print(a)
