Buggy python submission (verdict: Time Limit Exceeded):
def main():
    [N, M] = [int(number) for number in input().split()]
    part_times = []
    for i in range(N):
        job= [int(number) for number in input().split()]
        part_times.append(job)
    part_times = [part_time for part_time in sorted(part_times, key = lambda x: (x[1], x[0]), reverse=True)] #if part_time[0] <= M]
    money = 0
    #day = 0
    #earns = []
    for day in range(M):
        for part_time in part_times:
            if part_time[0] <= day + 1:
                money += part_time[1]
                part_times.remove(part_time)
                break
        """
        try:
            todays_part = next(itertools.ifilter(lambda x: x[0] <= day+1, part_times), None)
            money += todays_part[1]
            part_times.remove(todays_part)
        except:
            continue
        """

    """
    for [income_day, earn] in part_times:
        remain_day = M - day
        if remain_day >= income_day:
            money += earn
        else:
            min_earn = min(earns)
            if earn > min_earn:
                money += earn
                money -= min_earn
                earns.remove(min_earn)
        earns.append(earn)
        day += 1
    """
    print(money)

if __name__ == '__main__':
    main()


Fixed submission:
import heapq

def main():
    [N, M] = [int(number) for number in input().split()]
    part_times = []
    for i in range(N):
        job= [int(number) for number in input().split()]
        part_times.append(job)
    part_times = [part_time for part_time in sorted(part_times, key = lambda x: x[0])] #if part_time[0] <= M]
    money = 0
    hp = []
    for day in range(M):
        while part_times != [] and part_times[0][0] <= day + 1:
            part_time = part_times[0]
            heapq.heappush(hp, - part_time[1])
            part_times.pop(0)
        if hp != []:
            money -= heapq.heappop(hp)

    print(money)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    [N, M] = [int(number) for number in input().split()]
    part_times = []
    for i in range(N):
        job= [int(number) for number in input().split()]
        part_times.append(job)
    part_times = [part_time for part_time in sorted(part_times, key = lambda x: x[1], reverse=True) if part_time[0] <= M]
    money = 0
    #day = 0
    #earns = []
    for day in range(M):
        try:
            todays_part = list(filter(lambda x: x[0] <= day + 1, part_times))[0]
            money += todays_part[1]
            part_times.remove(todays_part)
        except:
            continue

    """
    for [income_day, earn] in part_times:
        remain_day = M - day
        if remain_day >= income_day:
            money += earn
        else:
            min_earn = min(earns)
            if earn > min_earn:
                money += earn
                money -= min_earn
                earns.remove(min_earn)
        earns.append(earn)
        day += 1
    """
    print(money)

if __name__ == '__main__':
    main()


Fixed submission:
import heapq

def main():
    [N, M] = [int(number) for number in input().split()]
    part_times = []
    for i in range(N):
        job= [int(number) for number in input().split()]
        part_times.append(job)
    part_times = [part_time for part_time in sorted(part_times, key = lambda x: x[0])] #if part_time[0] <= M]
    money = 0
    hp = []
    for day in range(M):
        while part_times != [] and part_times[0][0] <= day + 1:
            part_time = part_times[0]
            heapq.heappush(hp, - part_time[1])
            part_times.pop(0)
        if hp != []:
            money -= heapq.heappop(hp)

    print(money)

if __name__ == '__main__':
    main()