Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n,m=map(int, input().split())
a=[list(map(int, input().split())) for i in range(n)]
a.sort(key=lambda x: x[1],reverse=True)
x=[1 for i in range(m)]
ans=0
count=0
q=[]

for i in range(1,m+1):
    for j in range(n):
        if a[j][0]==i: 
            heapq.heappush(q,-a[j][1])
    
    if len(q)!=0:
        ans+=-heapq.heappop(q)
        
            

print(ans)

        


        
        
    
    
        



Fixed submission:
import heapq
def heapify(x):
    for i in reversed(range(n//2)):
        _siftup(x, i)
 
n,m = map(int,input().split())
 
l = []
for i in range(n):
    ab = list(map(int,input().split()))
    l.append(ab)
l.sort()
q = []
ans = 0
cnt = 0
for i in range(1,m+1):
    while cnt < n and l[cnt][0] == i:
        heapq.heappush(q,-l[cnt][1])
        cnt += 1
    
    if len(q) != 0:
        ans += -heapq.heappop(q)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int, input().split())
a=[list(map(int, input().split())) for i in range(n)]
a.sort(key=lambda x: x[1],reverse=True)
x=[1 for i in range(m)]
ans=0
count=0
for i in range(n):
    if a[i][0]<=m:
        for j in range(a[i][0]-1,m):
            if x[j]==1:
                ans+=a[i][1]
                x[j]=-1
                break
            

print(ans)

        


        
        
    
    
        



Fixed submission:
import heapq
def heapify(x):
    for i in reversed(range(n//2)):
        _siftup(x, i)
 
n,m = map(int,input().split())
 
l = []
for i in range(n):
    ab = list(map(int,input().split()))
    l.append(ab)
l.sort()
q = []
ans = 0
cnt = 0
for i in range(1,m+1):
    while cnt < n and l[cnt][0] == i:
        heapq.heappush(q,-l[cnt][1])
        cnt += 1
    
    if len(q) != 0:
        ans += -heapq.heappop(q)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
n,m = map(int,input().split())
 
l = []
for i in range(n):
    ab = list(map(int,input().split()))
    l.append(ab)
l.sort()
q = []
ans = 0
cnt = 0
for i in range(1,m+1):
    while cnt < n and l[cnt][0] == i:
        q.append(-l[cnt][1])
        q.sort()
        cnt += 1
    
    if len(q) != 0:
        ans +=-q.pop(0)
 
print(ans)

Fixed submission:
import heapq
def heapify(x):
    for i in reversed(range(n//2)):
        _siftup(x, i)
 
n,m = map(int,input().split())
 
l = []
for i in range(n):
    ab = list(map(int,input().split()))
    l.append(ab)
l.sort()
q = []
ans = 0
cnt = 0
for i in range(1,m+1):
    while cnt < n and l[cnt][0] == i:
        heapq.heappush(q,-l[cnt][1])
        cnt += 1
    
    if len(q) != 0:
        ans += -heapq.heappop(q)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
n,m = map(int,input().split())
 
l = []
for i in range(n):
    ab = list(map(int,input().split()))
    l.append(ab)
l.sort()
q = []
ans = 0
cnt = 0
for i in range(1,m+1):
    while cnt < n and l[cnt][0] == i:
        q.append(-l[cnt][1])
        q.sort()
        cnt += 1
    
    if len(q) != 0:
        ans +=-q.pop(0)
 
print(ans)

Fixed submission:
import heapq
def heapify(x):
    for i in reversed(range(n//2)):
        _siftup(x, i)
 
n,m = map(int,input().split())
 
l = []
for i in range(n):
    ab = list(map(int,input().split()))
    l.append(ab)
l.sort()
q = []
ans = 0
cnt = 0
for i in range(1,m+1):
    while cnt < n and l[cnt][0] == i:
        heapq.heappush(q,-l[cnt][1])
        cnt += 1
    
    if len(q) != 0:
        ans += -heapq.heappop(q)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int, input().split()) 
ab=[list(map(int, input().split())) for i in range(n)]
ans=0

x=sorted(ab, key=lambda x :x[1])
x.reverse()

v=[i for i in range(1,m+1)]


for i in range(n):
    if len(v)==0:
        break
    for j in range(m):
        if v[-1]>=x[i][0]:
            if v[j]>=x[i][0]:
                ans+=x[i][1]
                del v[j]
                break
        
print(ans)

Fixed submission:
import heapq
def heapify(x):
    for i in reversed(range(n//2)):
        _siftup(x, i)
 
n,m = map(int,input().split())
 
l = []
for i in range(n):
    ab = list(map(int,input().split()))
    l.append(ab)
l.sort()
q = []
ans = 0
cnt = 0
for i in range(1,m+1):
    while cnt < n and l[cnt][0] == i:
        heapq.heappush(q,-l[cnt][1])
        cnt += 1
    
    if len(q) != 0:
        ans += -heapq.heappop(q)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int, input().split()) 
ab=[list(map(int, input().split())) for i in range(n)]
ans=0
 
x=sorted(ab, key=lambda x :x[1])
x.reverse()
 
v=[]
for i in range(1,m+1):
    v.append(i)
 
for i in range(min(m,n)):
    if len(v)==0:
        break
    if x[i][0]<=v[-1]:
        ans+=x[i][1]
        for j in range(m):
            if v[j]>=x[i][0]:
                del v[j]
                break
    else:
        continue
print(ans)

Fixed submission:
import heapq
def heapify(x):
    for i in reversed(range(n//2)):
        _siftup(x, i)
 
n,m = map(int,input().split())
 
l = []
for i in range(n):
    ab = list(map(int,input().split()))
    l.append(ab)
l.sort()
q = []
ans = 0
cnt = 0
for i in range(1,m+1):
    while cnt < n and l[cnt][0] == i:
        heapq.heappush(q,-l[cnt][1])
        cnt += 1
    
    if len(q) != 0:
        ans += -heapq.heappop(q)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int, input().split()) 
ab=[list(map(int, input().split())) for i in range(n)]
ans=0

x=sorted(ab, key=lambda x :x[1])
x.reverse()

v=[]
for i in range(1,m+1):
    v.append(i)

for i in range(n):
    if len(v)==0:
        break
    for j in range(m):
        if v[-1]>=x[i][0]:
            if v[j]>=x[i][0]:
                ans+=x[i][1]
                del v[j]
                break
        else:
            pass
        
print(ans)

Fixed submission:
import heapq
def heapify(x):
    for i in reversed(range(n//2)):
        _siftup(x, i)
 
n,m = map(int,input().split())
 
l = []
for i in range(n):
    ab = list(map(int,input().split()))
    l.append(ab)
l.sort()
q = []
ans = 0
cnt = 0
for i in range(1,m+1):
    while cnt < n and l[cnt][0] == i:
        heapq.heappush(q,-l[cnt][1])
        cnt += 1
    
    if len(q) != 0:
        ans += -heapq.heappop(q)
 
print(ans)