Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
ab.sort()
hq = []
result = 0
j = 0
for i in range(1, m + 1):
    for a, b in ab[j:]:
        if a > i:
            break
        heappush(hq, -b)
        j += 1
    if hq:
        result -= heappop(hq)
print(result)

Fixed submission:
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
ab.sort()
hq = []
result = 0
j = 0
for i in range(1, m + 1):
    while j < n and ab[j][0] <= i:
        heappush(hq, -ab[j][1])
        j += 1
    if hq:
        result -= heappop(hq)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
ab.sort(key=lambda x: (x[0], -x[1]))
hq = []
result = 0
for i in range(1, m + 1):
    j = 0
    for a, b in ab:
        if a > i:
            break
        j += 1
        heappush(hq, -b)
    ab = ab[j:]
    if hq:
        result -= heappop(hq)
print(result)

Fixed submission:
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
ab.sort()
hq = []
result = 0
j = 0
for i in range(1, m + 1):
    while j < n and ab[j][0] <= i:
        heappush(hq, -ab[j][1])
        j += 1
    if hq:
        result -= heappop(hq)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
ab.sort(key=lambda x: (x[0], -x[1]))
hq = []
result = 0
for i in range(1, m + 1):
    j = 0
    for a, b in ab:
        if a > i:
            break
        j += 1
        heappush(hq, -b)
    ab = ab[j:]
    if hq:
        result -= heappop(hq)
print(result)

Fixed submission:
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
ab.sort()
hq = []
result = 0
j = 0
for i in range(1, m + 1):
    while j < n and ab[j][0] <= i:
        heappush(hq, -ab[j][1])
        j += 1
    if hq:
        result -= heappop(hq)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
pab = [(i, k[0], k[1]) for i, k in enumerate(sorted(ab, key=lambda x: (-x[1], x[0])))]
hq = []
result = 0
for i in range(1, m + 1):
    for j in [k for k in pab if k[1] == i]:
        heappush(hq, j)
    if hq:
        result += heappop(hq)[2]
print(result)

Fixed submission:
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
ab.sort()
hq = []
result = 0
j = 0
for i in range(1, m + 1):
    while j < n and ab[j][0] <= i:
        heappush(hq, -ab[j][1])
        j += 1
    if hq:
        result -= heappop(hq)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
pab = [(i, k[0], k[1]) for i, k in enumerate(sorted(ab, key=lambda x: (-x[1], x[0])))]
hq = []
result = 0
for i in range(1, m + 1):
    for j in [k for k in pab if k[1] == i]:
        heappush(hq, j)
    if hq:
        result += heappop(hq)[2]
print(result)

Fixed submission:
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
ab.sort()
hq = []
result = 0
j = 0
for i in range(1, m + 1):
    while j < n and ab[j][0] <= i:
        heappush(hq, -ab[j][1])
        j += 1
    if hq:
        result -= heappop(hq)
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
ab.sort(key=lambda x: x[1], reverse=True)
result = 0
for i in range(1, m + 1):
    value = [k for k in ab if k[0] <= i]
    if value:
        result += value[0][1]
        ab.remove(value[0])
print(result)

Fixed submission:
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
ab.sort()
hq = []
result = 0
j = 0
for i in range(1, m + 1):
    while j < n and ab[j][0] <= i:
        heappush(hq, -ab[j][1])
        j += 1
    if hq:
        result -= heappop(hq)
print(result)