Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
ans = 0
hq = []
for i in range(1, m+1):
    for a, b in ab:
        if a == i:
            heappush(hq, (-b, a))
        
    if len(hq) != 0:
        ans -= heappop(hq)[0]
    
print(ans)

Fixed submission:
from heapq import heappush, heappop

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

ab.sort()
ans = 0
hq = []
idx = 0
for i in range(1, m+1):
    for j in range(idx, n):
        if ab[j][0] == i:
            heappush(hq, (-ab[j][1], ab[j][0]))
            idx += 1
        else:
            break
    if len(hq) != 0:
        ans -= heappop(hq)[0]
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

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

ans = 0
hq = []
for i in range(1, m+1):
    for a, b in ab:
        if a == i:
            heappush(hq, (-b, a))
    
    if len(hq) != 0:
        ans -= heappop(hq)[0]
    
print(ans)

Fixed submission:
from heapq import heappush, heappop

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

ab.sort()
ans = 0
hq = []
idx = 0
for i in range(1, m+1):
    for j in range(idx, n):
        if ab[j][0] == i:
            heappush(hq, (-ab[j][1], ab[j][0]))
            idx += 1
        else:
            break
    if len(hq) != 0:
        ans -= heappop(hq)[0]
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

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

ans = 0
hq = []
for i in range(1, m+1):
    for a, b in ab:
        if a == i:
            heappush(hq, (-b, a))
    
    if len(hq) != 0:
        ans -= heappop(hq)[0]
    
print(ans)

Fixed submission:
from heapq import heappush, heappop

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

ab.sort()
ans = 0
hq = []
idx = 0
for i in range(1, m+1):
    for j in range(idx, n):
        if ab[j][0] == i:
            heappush(hq, (-ab[j][1], ab[j][0]))
            idx += 1
        else:
            break
    if len(hq) != 0:
        ans -= heappop(hq)[0]
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

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

ans = 0
hq = []
for i in range(1, m+1):
    for a, b in ab:
        if a == i and not -b in hq:
            heappush(hq, (-b, a))
    
    if len(hq) != 0:
        ans -= heappop(hq)[0]
    
print(ans)

Fixed submission:
from heapq import heappush, heappop

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

ab.sort()
ans = 0
hq = []
idx = 0
for i in range(1, m+1):
    for j in range(idx, n):
        if ab[j][0] == i:
            heappush(hq, (-ab[j][1], ab[j][0]))
            idx += 1
        else:
            break
    if len(hq) != 0:
        ans -= heappop(hq)[0]
    
print(ans)