import heapq
N, M = map(int, input().split())
edge_list = [[] for i in range(N+1)]
for i in range(2, N + 1):
    edge_list[i].append((0, i-1))
for i in range(M):
    L, R, C = map(int, input().split())
    edge_list[L].append((C, R))
def solve(s, t):
    fixed = {}
    q = []
    heapq.heappush(q, (0, s))
    while q:
        w, x = heapq.heappop(q)
        if x == t:
            return w
        if x in fixed:
            continue
        fixed[x] = w
        for c, y in edge_list[x]:
            if y not in fixed:
                heapq.heappush(q, (w + c, y))
    return None

answer = solve(1, N)
if answer is None:
    print(-1)
else:
    print(answer)