N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    l, r, c = map(int, input().split())
    l, r = l - 1, r - 1
    G[l].append([r, c])

for i in range(1, N):
    G[i].append([i - 1, 0])


def dijkstra(graph, start, inf=float('inf')):
    import heapq
    n = len(graph)
    distances = [inf] * n
    distances[start] = 0
    visited = [False] * n

    # 距離・頂点
    hq = [(0, start)]
    while hq:
        dist, fr = heapq.heappop(hq)
        visited[fr] = True

        for to, cost in graph[fr]:
            new_dist = distances[fr] + cost
            if (visited[to]) or (distances[to] <= new_dist):
                continue

            distances[to] = new_dist
            heapq.heappush(hq, (new_dist, to))

    return distances


ans = dijkstra(G, 0)[N - 1]
print(ans if ans != float('inf') else -1)
