import heapq
 
def dijkstras(graph):
    cost = [10 ** 9 for _ in range(len(graph))]
    start = 0
    cost[start] = 0
    queue = [(cost[start], start)]
    while queue:
        edge_from_cost, edge_from = heapq.heappop(queue)
        if cost[edge_from] < edge_from_cost: continue
        for edge_to, edge_to_cost in graph[edge_from]:
            if cost[edge_to] > edge_from_cost + edge_to_cost:
                cost[edge_to] = cost[edge_from] + edge_to_cost
                heapq.heappush(queue, (cost[edge_to], edge_to))
 
    return cost
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
reverse_graph = [[] for _ in range(m)]
for i in range(m):
    l, r, c = map(int, input().split())
    l -= 1
    r -= 1
    graph[l].append((r, c))
    for j in range(l+1,r+1):
        graph[r].append((j,0))
print(dijkstras(graph)[n-1])