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

L = [[int(a) for a in input().split()] for _ in range(N)]



import heapq



L.sort()

h = []

ans = [0]*(M)

i = 0

j = 0

d = 0

while i < M and d < M:

    i += 1

    while j < N and L[j][0] <= i:

        heapq.heappush(h, [-L[j][1], L[j][0]])

        j += 1

    if h:

        temp = heapq.heappop(h)

        ans[i-1] = -temp[0]

    

if N < M:

    ans.sort(reverse=True)

    c = 0

    for i in range(N):

        c += ans[i]

    print(c)

else:

    print((sum(ans)))
N,M = list(map(int, input().split()))

L = [[int(l) for l in input().split()] for _ in range(N)]



import heapq

h = []

ans = 0

L.sort()

m = 1

i = 0

while i < N and L[i][0] <= M:

    if L[i][0] == m:

        heapq.heappush(h, -L[i][1])

        i += 1

    else:

        m += 1

        if h:

            ans -= heapq.heappop(h)

while m <= M and h:

    ans -= heapq.heappop(h)

    m += 1

print(ans)
N, M = list(map(int, input().split()))
L = [[int(a) for a in input().split()] for _ in range(N)]
import heapq

L.sort()
h = []
ans = [0] * (M)
i = 0
j = 0
d = 0
while i < M and d < M:
    i += 1
    while j < N and L[j][0] <= i:
        heapq.heappush(h, [-L[j][1], L[j][0]])
        j += 1
    if h:
        temp = heapq.heappop(h)
        ans[i - 1] = -temp[0]
if N < M:
    ans.sort(reverse=True)
    c = 0
    for i in range(N):
        c += ans[i]
    print(c)
else:
    print((sum(ans)))

N, M = list(map(int, input().split()))
L = [[int(l) for l in input().split()] for _ in range(N)]
import heapq

h = []
ans = 0
L.sort()
m = 1
i = 0
while i < N and L[i][0] <= M:
    if L[i][0] == m:
        heapq.heappush(h, -L[i][1])
        i += 1
    else:
        m += 1
        if h:
            ans -= heapq.heappop(h)
while m <= M and h:
    ans -= heapq.heappop(h)
    m += 1
print(ans)

-L = [[int(a) for a in input().split()] for _ in range(N)] +L = [[int(l) for l in input().split()] for _ in range(N)] +h = [] +ans = 0 -h = [] -ans = [0] * (M) +m = 1 -j = 0 -d = 0 -while i < M and d < M: -    i += 1 -    while j < N and L[j][0] <= i: -        heapq.heappush(h, [-L[j][1], L[j][0]]) -        j += 1 -    if h: -        temp = heapq.heappop(h) -        ans[i - 1] = -temp[0] -if N < M: -    ans.sort(reverse=True) -    c = 0 -    for i in range(N): -        c += ans[i] -    print(c) -else: -    print((sum(ans))) +while i < N and L[i][0] <= M: +    if L[i][0] == m: +        heapq.heappush(h, -L[i][1]) +        i += 1 +    else: +        m += 1 +        if h: +            ans -= heapq.heappop(h) +while m <= M and h: +    ans -= heapq.heappop(h) +    m += 1 +print(ans)