Buggy python submission (verdict: Time Limit Exceeded):
N,M = input().split()
N,M = int(N),int(M)
f_start = [0 for i in range(N)]
A,B = [],[]
import heapq
for i in range(N):
    a,b = input().split()
    a,b = int(a),int(b)
    A.append(a)
    B.append(-b)
    
def add(q_,add_):
    for i in range(len(add_)):
        heapq.heappush(q_,add_[i])

def kouho(A,B,m):
    kouho_list = []
    for i in range(len(B)):
        if(A[i]==m):
            kouho_list.append(B[i])
    return kouho_list

q = []
heapq.heapify(q)
sum_money = 0

for m in range(1,M+1):
    kouho_list = kouho(A,B,m)
    add(q,kouho_list)
    #print(q)
    if(len(q)>0):
        sum_money += -heapq.heappop(q)
print(sum_money)

Fixed submission:
N,M = input().split()
N,M = int(N),int(M)
f_start = [0 for i in range(N)]
A,B = [],[]
import heapq
for i in range(N):
    a,b = input().split()
    a,b = int(a),int(b)
    A.append(a)
    B.append(-b)
    
def add(q_,add_):
    for i in range(len(add_)):
        heapq.heappush(q_,add_[i])

def kouho(A,B,M):
    kouho_list = [[] for i in range(M+1)]
    for i in range(len(A)):
        if(A[i]<=M):
            kouho_list[A[i]].append(B[i])
    return kouho_list

q = []
heapq.heapify(q)
sum_money = 0

kouho_list = kouho(A,B,M)
for m in range(1,M+1):
    kouho_ = kouho_list[m]
    add(q,kouho_)
    #print(q)
    if(len(q)>0):
        sum_money += -heapq.heappop(q)
print(sum_money)

Buggy python submission (verdict: Runtime Error):
N,M = input().split()
N,M = int(N),int(M)
f_start = [0 for i in range(N)]
A,B = [],[]
for i in range(N):
    a,b = input().split()
    a,b = int(a),int(b)
    A.append(a)
    B.append(-b)
    
def add(q_,add_):
    for i in range(len(add_)):
        heapq.heappush(q_,add_[i])

def kouho(A,B,m):
    kouho_list = []
    for i in range(len(B)):
        if(A[i]==m):
            kouho_list.append(B[i])
    return kouho_list

q = []
heapq.heapify(q)
sum_money = 0

for m in range(1,M+1):
    kouho_list = kouho(A,B,m)
    add(q,kouho_list)
    #print(q)
    if(len(q)>0):
        sum_money += -heapq.heappop(q)
print(sum_money)

Fixed submission:
N,M = input().split()
N,M = int(N),int(M)
f_start = [0 for i in range(N)]
A,B = [],[]
import heapq
for i in range(N):
    a,b = input().split()
    a,b = int(a),int(b)
    A.append(a)
    B.append(-b)
    
def add(q_,add_):
    for i in range(len(add_)):
        heapq.heappush(q_,add_[i])

def kouho(A,B,M):
    kouho_list = [[] for i in range(M+1)]
    for i in range(len(A)):
        if(A[i]<=M):
            kouho_list[A[i]].append(B[i])
    return kouho_list

q = []
heapq.heapify(q)
sum_money = 0

kouho_list = kouho(A,B,M)
for m in range(1,M+1):
    kouho_ = kouho_list[m]
    add(q,kouho_)
    #print(q)
    if(len(q)>0):
        sum_money += -heapq.heappop(q)
print(sum_money)

Buggy python submission (verdict: Runtime Error):
#f:やったことのある仕事=1そうでない=0
N,M = input().split()
N,M = int(N),int(M)
f_start = [0 for i in range(N)]
A,B = [],[]
for i in range(N):
    a,b = input().split()
    a,b = int(a),int(b)
    A.append(a)
    B.append(b)
    
def dp(m,f):
    if(m==0):
        return 0
    else:
        max_ = 0
        for i in range(len(A)):
            if(f[i] == 0 and A[i]<=m):
                f_co = f.copy()
                f_co[i] = 1
                max_ = max([max_,dp(m-1,f_co)+B[i]])
        
        return max_
    
print(dp(M,f_start))

Fixed submission:
N,M = input().split()
N,M = int(N),int(M)
f_start = [0 for i in range(N)]
A,B = [],[]
import heapq
for i in range(N):
    a,b = input().split()
    a,b = int(a),int(b)
    A.append(a)
    B.append(-b)
    
def add(q_,add_):
    for i in range(len(add_)):
        heapq.heappush(q_,add_[i])

def kouho(A,B,M):
    kouho_list = [[] for i in range(M+1)]
    for i in range(len(A)):
        if(A[i]<=M):
            kouho_list[A[i]].append(B[i])
    return kouho_list

q = []
heapq.heapify(q)
sum_money = 0

kouho_list = kouho(A,B,M)
for m in range(1,M+1):
    kouho_ = kouho_list[m]
    add(q,kouho_)
    #print(q)
    if(len(q)>0):
        sum_money += -heapq.heappop(q)
print(sum_money)