Buggy python submission (verdict: Time Limit Exceeded):
n,m = list(map(lambda x: int(x), input().split()))

jobs = []
for i in range(n):
    a,b = list(map(lambda x: int(x), input().split()))
    jobs.append([b,a])

# 貪欲解法
# 最終日から決める
jobs.sort()
jobs.reverse()
ans = 0
for i in range(m+1):
    # 給料大きい順にみて、振り込みがi+1以内なら働く
    for j in range(len(jobs)):
        if jobs[j][1] < i+1:
            ans += jobs[j][0]
            del jobs[j]
            break

            
print (ans)

Fixed submission:
import heapq

n,m = list(map(lambda x: int(x), input().split()))

jobs = {}
for i in range(n):
    a,b = list(map(lambda x: int(x), input().split()))
    if a in jobs.keys():
        jobs[a].append(b)
    else:
        jobs[a] = [b]

# 貪欲解法
# 最終日から決める
ans = 0
day = m

possible_job = []
# heapqでjobを管理すれば現時点で最大の給与を得ることのできる仕事を容易に取り出せる
for i in range(m+1):
    if i in jobs.keys():
        for x in jobs[i]:
            heapq.heappush(possible_job, -1 * x)
    if len(possible_job)>0:
        day_work = heapq.heappop(possible_job)
        ans += -1 * day_work
    
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = list(map(lambda x: int(x), input().split()))

jobs = []
for i in range(n):
    jobs.append(list(map(lambda x: int(x), input().split())))

# 貪欲解法
# 最終日から決める
jobs.sort()
selected = []
ans = 0
for i in range(m+1):
    # 振込までi+1日以内の仕事のうち最大の仕事を選び働く
    max_reward = 0
    max_job = -1
    for j in range(n):
        if jobs[j][0] < i+1:
            if max_reward <= jobs[j][1]:
                max_reward = max([max_reward, jobs[j][1]])
                max_job = j
        else:
            break
    ans += max_reward
    if max_job != -1:
        jobs[max_job][1] = 0

print (ans)

Fixed submission:
import heapq

n,m = list(map(lambda x: int(x), input().split()))

jobs = {}
for i in range(n):
    a,b = list(map(lambda x: int(x), input().split()))
    if a in jobs.keys():
        jobs[a].append(b)
    else:
        jobs[a] = [b]

# 貪欲解法
# 最終日から決める
ans = 0
day = m

possible_job = []
# heapqでjobを管理すれば現時点で最大の給与を得ることのできる仕事を容易に取り出せる
for i in range(m+1):
    if i in jobs.keys():
        for x in jobs[i]:
            heapq.heappush(possible_job, -1 * x)
    if len(possible_job)>0:
        day_work = heapq.heappop(possible_job)
        ans += -1 * day_work
    
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = list(map(lambda x: int(x), input().split()))

jobs = []
for i in range(n):
    jobs.append(list(map(lambda x: int(x), input().split())))

# 貪欲解法
# 最終日から決める
jobs.sort()
selected = []
ans = 0
for i in range(m+1):
    # 振込までi+1日以内の仕事のうち最大の仕事を選び働く
    max_reward = 0
    max_job = -1
    for j in range(n):
        if jobs[j][0] < i+1:
            if max_reward <= jobs[j][1]:
                max_reward = max([max_reward, jobs[j][1]])
                max_job = j
        else:
            break
    ans += max_reward
    if max_job != -1:
        jobs[max_job][1] = 0

print (ans)

Fixed submission:
import heapq

n,m = list(map(lambda x: int(x), input().split()))

jobs = {}
for i in range(n):
    a,b = list(map(lambda x: int(x), input().split()))
    if a in jobs.keys():
        jobs[a].append(b)
    else:
        jobs[a] = [b]

# 貪欲解法
# 最終日から決める
ans = 0
day = m

possible_job = []
# heapqでjobを管理すれば現時点で最大の給与を得ることのできる仕事を容易に取り出せる
for i in range(m+1):
    if i in jobs.keys():
        for x in jobs[i]:
            heapq.heappush(possible_job, -1 * x)
    if len(possible_job)>0:
        day_work = heapq.heappop(possible_job)
        ans += -1 * day_work
    
print (ans)