L=lambda:list(map(int,input().split()));n,m=L();t=sorted([L()for _ in range(n)]+[[float("inf")]]);import heapq as q;h=[];a=j=0

for i in range(t[0][0],m+1):

  while t[j][0]==i:q.heappush(h,-t[j][1]);j+=1

  if h:a-=q.heappop(h)

print(a)
n,m=list(map(int,input().split()))

ab=[list(map(int,input().split()))for _ in range(n)]+[[100000000,0]]

for i in range(m):ab.append([i+1,0])

ab.sort()

from heapq import heappop,heappush

h=[]

j=0

ans=0

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

  while ab[j][0]<=i:

    heappush(h,-ab[j][1])

    j+=1

  ans-=heappop(h)

print(ans)
L = lambda: list(map(int, input().split()))
n, m = L()
t = sorted([L() for _ in range(n)] + [[float("inf")]])
import heapq as q

h = []
a = j = 0
for i in range(t[0][0], m + 1):
    while t[j][0] == i:
        q.heappush(h, -t[j][1])
        j += 1
    if h:
        a -= q.heappop(h)
print(a)

n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)] + [[100000000, 0]]
for i in range(m):
    ab.append([i + 1, 0])
ab.sort()
from heapq import heappop, heappush

h = []
j = 0
ans = 0
for i in range(1, m + 1):
    while ab[j][0] <= i:
        heappush(h, -ab[j][1])
        j += 1
    ans -= heappop(h)
print(ans)

-L = lambda: list(map(int, input().split())) -n, m = L() -t = sorted([L() for _ in range(n)] + [[float("inf")]]) -import heapq as q +n, m = list(map(int, input().split())) +ab = [list(map(int, input().split())) for _ in range(n)] + [[100000000, 0]] +for i in range(m): +    ab.append([i + 1, 0]) +ab.sort() +from heapq import heappop, heappush -a = j = 0 -for i in range(t[0][0], m + 1): -    while t[j][0] == i: -        q.heappush(h, -t[j][1]) +j = 0 +ans = 0 +for i in range(1, m + 1): +    while ab[j][0] <= i: +        heappush(h, -ab[j][1]) -    if h: -        a -= q.heappop(h) -print(a) +    ans -= heappop(h) +print(ans)