Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
from collections import deque
import numpy as np

N, M = [int(x) for x in stdin.readline().rstrip().split()]
AB = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
AB.sort(key=lambda x: (x[0], -x[1]))
work = [deque([]) for _ in range(M + 1)]

for ab in AB:
    if ab[0] <= M:
        work[ab[0]].append(ab[1])

ans = 0
day = 1
max_work = np.array([])
while day <= M:
    w = 0
    tmp = 0
    max_work = max_work.tolist()
    if len(work[day]) > 0:
        max_work.append(work[day][0])
    else:
        max_work.append(-1)
    max_work = np.asarray(max_work)
    a = np.argmax(max_work) + 1
    if max_work[a - 1] > 0:
        ans += max_work[a - 1]
        work[a].popleft()
        if len(work[a]) > 0:
            max_work[a - 1] = work[a][0]
        else:
            max_work[a - 1] = -1
    day += 1

print(ans)

Fixed submission:
from sys import stdin
from collections import deque
import heapq


N, M = [int(x) for x in stdin.readline().rstrip().split()]
AB = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
AB.sort(key=lambda x: (x[0], -x[1]))
work = [deque([]) for _ in range(M + 1)]

for ab in AB:
    if ab[0] <= M:
        work[ab[0]].append(ab[1])

ans = 0
day = 1
available_work = []
while day <= M:
    for w in work[day]:
        heapq.heappush(available_work, -w)
    if len(available_work) > 0:
        ans += heapq.heappop(available_work)
    day += 1

print(-ans)

Buggy python submission (verdict: Runtime Error):
from sys import stdin
from collections import deque
import numpy as np

N, M = [int(x) for x in stdin.readline().rstrip().split()]
AB = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
AB.sort(key=lambda x: (x[0], -x[1]))
work = [deque([]) for _ in range(M + 1)]

for ab in AB:
    if ab[0] <= M:
        work[ab[0]].append(ab[1])

ans = 0
day = 1
max_work = np.array([])
while day <= M:
    w = 0
    tmp = 0
    max_work = max_work.tolist()
    if len(work[day]) > 0:
        max_work.append(work[day][0])
    else:
        max_work.append(-1)
    max_work = np.asarray(max_work)
    a = np.argmax(max_work) + 1
    if max_work[a - 1] > 0:
        ans += max_work[a - 1]
        work[a].popleft()
        if len(work[a]) > 0:
            max_work[a - 1] = work[a][0]
        else:
            max_work[a - 1] = -1
    day += 1

print(ans)

Fixed submission:
from sys import stdin
from collections import deque
import heapq


N, M = [int(x) for x in stdin.readline().rstrip().split()]
AB = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
AB.sort(key=lambda x: (x[0], -x[1]))
work = [deque([]) for _ in range(M + 1)]

for ab in AB:
    if ab[0] <= M:
        work[ab[0]].append(ab[1])

ans = 0
day = 1
available_work = []
while day <= M:
    for w in work[day]:
        heapq.heappush(available_work, -w)
    if len(available_work) > 0:
        ans += heapq.heappop(available_work)
    day += 1

print(-ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
from collections import deque

N, M = [int(x) for x in stdin.readline().rstrip().split()]
AB = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
AB.sort(key=lambda x: (x[0], -x[1]))
work = [deque([]) for _ in range(M + 1)]

for ab in AB:
    if ab[0] <= M:
        work[ab[0]].append(ab[1])

ans = 0
day = 1
while day <= M:
    w = 0
    tmp = 0
    for d in range(1, day + 1):
        if len(work[d]) > 0 and work[d][0] > w:
            w = work[d][0]
            tmp = d
    if tmp > 0:
        work[tmp].popleft()
    ans += w
    day += 1

print(ans)


Fixed submission:
from sys import stdin
from collections import deque
import heapq


N, M = [int(x) for x in stdin.readline().rstrip().split()]
AB = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
AB.sort(key=lambda x: (x[0], -x[1]))
work = [deque([]) for _ in range(M + 1)]

for ab in AB:
    if ab[0] <= M:
        work[ab[0]].append(ab[1])

ans = 0
day = 1
available_work = []
while day <= M:
    for w in work[day]:
        heapq.heappush(available_work, -w)
    if len(available_work) > 0:
        ans += heapq.heappop(available_work)
    day += 1

print(-ans)