Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter
N,M = [int(x) for x in input().split()]
LRC = []
event = []
dists = [float('inf')]*N
dists[0] = 0
cnt_key = 0
for _ in range(M):
    l, r, c = [int(x) for x in input().split()]
    event.append((l-1, c, 1, cnt_key))
    event.append((r-1, c, -1, cnt_key))
    cnt_key += 1

event.sort(key=itemgetter(0))
paths = {}
now_dist = 0
for ev in event:
    x = ev[0]
    for s in paths:
        if(dists[x]<paths[s][1]):
            paths[s][1] = dists[x]
        dists[x] = min(dists[x], paths[s][0]+paths[s][1])

    if(ev[2]==1):
        paths[ev[3]] = [ev[1], dists[ev[0]]]
    else:
        del paths[ev[3]]

if(dists[-1]==float('inf')):
    print(-1)
else:
    print(dists[-1])


Fixed submission:
from operator import itemgetter
from collections import defaultdict
from heapq import heappop, heappush

class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()

class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

N,M = [int(x) for x in input().split()]
graph = Graph()
for n in range(N):
    graph.add_edge(n+1, n, 0)
for _ in range(M):
    l, r, c = [int(x) for x in input().split()]
    graph.add_edge(l-1, r-1, weight=c)

dijkstra = Dijkstra(graph, 0)
ans = dijkstra.shortest_distance(N-1)
if(ans == float('inf')):
    print(-1)
else:
    print(ans)

Buggy python submission (verdict: Runtime Error):
from operator import itemgetter
N,M = [int(x) for x in input().split()]
LRC = []
event = []
dists = [float('inf')]*N
dists[0] = 0
cnt_key = 0
for _ in range(M):
    l, r, c = [int(x) for x in input().split()]
    event.append((l-1, c, 1, cnt_key))
    event.append((r-1, c, -1, cnt_key))
    cnt_key += 1

event.sort(key=itemgetter(0))
paths = {}
now_dist = 0
for ev in event:
    x = ev[0]
    for s in paths:
        if(dists[x]<paths[s][1]):
            paths[s][1] = dists[x]
        dists[x] = min(dists[x], paths[s][0]+paths[s][1])

    if(ev[2]==1):
        paths[ev[3]] = [ev[1], dists[ev[0]]]
    else:
        del paths[ev[3]]

if(dist[-1]==float('inf')):
    print(-1)
else:
    print(dist[-1])


Fixed submission:
from operator import itemgetter
from collections import defaultdict
from heapq import heappop, heappush

class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()

class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

N,M = [int(x) for x in input().split()]
graph = Graph()
for n in range(N):
    graph.add_edge(n+1, n, 0)
for _ in range(M):
    l, r, c = [int(x) for x in input().split()]
    graph.add_edge(l-1, r-1, weight=c)

dijkstra = Dijkstra(graph, 0)
ans = dijkstra.shortest_distance(N-1)
if(ans == float('inf')):
    print(-1)
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter
N,M = [int(x) for x in input().split()]
LRC = [[int(x) for x in input().split()] for _ in range(M)]
LRC.sort(key=itemgetter(0))
dist = [float('inf')] * N
dist[0] = 0
for l,r,c in LRC:
    fr = min(dist[l-1:r])
    for x in range(l-1,r):
        dist[x] = min(dist[x], fr+c)

if(dist[-1]==float('inf')):
    print(-1)
else:
    print(dist[-1])


Fixed submission:
from operator import itemgetter
from collections import defaultdict
from heapq import heappop, heappush

class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()

class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

N,M = [int(x) for x in input().split()]
graph = Graph()
for n in range(N):
    graph.add_edge(n+1, n, 0)
for _ in range(M):
    l, r, c = [int(x) for x in input().split()]
    graph.add_edge(l-1, r-1, weight=c)

dijkstra = Dijkstra(graph, 0)
ans = dijkstra.shortest_distance(N-1)
if(ans == float('inf')):
    print(-1)
else:
    print(ans)