Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop
N, M = map(int, input().split())
Data = [list(map(int, input().split())) for _ in range(N)]

heap = [0] * M
ans = 0
for i in range(1, M+1):
    N = len(Data)
    for j in range(N-1, -1, -1):
        if (Data[j][0] <= i):
            heappush(heap, -(Data.pop(j)[1]))

    ans += -(heappop(heap))

print(ans)


Fixed submission:
from heapq import heappush, heappop
N, M = map(int, input().split())

Data = [list(map(int, input().split())) for _ in range(N)]
Data.sort(reverse = True)

heap = [0] * M
ans = 0
for i in range(1, M+1):
    N = len(Data)
    for j in range(N-1, -1, -1):
        if Data[j][0] > i:
            break
        if (Data[j][0] <= i):
            heappush(heap, -(Data.pop(j)[1]))

    ans += -(heappop(heap))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# M日後に最大の値
from heapq import heappush, heappop
N, M = map(int, input().split())
# [0] -> 日数, [1] -> お金
Data = [list(map(int, input().split())) for _ in range(N)]

heap = []
ans = 0
for i in range(1, M+1):
    N = len(Data)

    for j in range(N-1, -1, -1):  #range(N)
        if (Data[j][0] <= i):
            iranai = Data.pop(j)
            heappush(heap, -(iranai[1]))

    if len(heap) != 0:
        ans += -(heappop(heap))

print(ans)


Fixed submission:
from heapq import heappush, heappop
N, M = map(int, input().split())

Data = [list(map(int, input().split())) for _ in range(N)]
Data.sort(reverse = True)

heap = [0] * M
ans = 0
for i in range(1, M+1):
    N = len(Data)
    for j in range(N-1, -1, -1):
        if Data[j][0] > i:
            break
        if (Data[j][0] <= i):
            heappush(heap, -(Data.pop(j)[1]))

    ans += -(heappop(heap))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# M日後に最大の値
N, M = map(int, input().split())
# [0] -> 日数, [1] -> お金
Data = [list(map(int, input().split())) for _ in range(N)]

temp = []
ans = 0
for i in range(1, M+1):
    N = len(Data)

    for j in range(N-1, -1, -1):  #range(N)
        if (Data[j][0] <= i):
            iranai = Data.pop(j)
            temp.append(iranai[1])

    if len(temp) != 0:
        ans += max(temp)
        temp.remove(max(temp))
print(ans)


Fixed submission:
from heapq import heappush, heappop
N, M = map(int, input().split())

Data = [list(map(int, input().split())) for _ in range(N)]
Data.sort(reverse = True)

heap = [0] * M
ans = 0
for i in range(1, M+1):
    N = len(Data)
    for j in range(N-1, -1, -1):
        if Data[j][0] > i:
            break
        if (Data[j][0] <= i):
            heappush(heap, -(Data.pop(j)[1]))

    ans += -(heappop(heap))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# M日後に最大の値
N, M = map(int, input().split())
# [0] -> 日数, [1] -> お金
Data = [list(map(int, input().split())) for _ in range(N)]

ans = 0
for i in range(1, M+1):
    temp = 0
    index = -1
    for j in range(len(Data)):
        if (Data[j][0] <= i) and (temp < Data[j][1]):
            temp = Data[j][1]
            index = j
    if index != -1:
        ans += temp
        Data[index][1] = -1
print(ans)


Fixed submission:
from heapq import heappush, heappop
N, M = map(int, input().split())

Data = [list(map(int, input().split())) for _ in range(N)]
Data.sort(reverse = True)

heap = [0] * M
ans = 0
for i in range(1, M+1):
    N = len(Data)
    for j in range(N-1, -1, -1):
        if Data[j][0] > i:
            break
        if (Data[j][0] <= i):
            heappush(heap, -(Data.pop(j)[1]))

    ans += -(heappop(heap))

print(ans)