import sys
input = sys.stdin.readline

INF = 10**18

def dijkstra(edges, size, src):
    from heapq import heappush, heappop

    dist = [INF] * size
    dist[src] = 0
    pq = [(0, src)]
    while pq:
        d, v = heappop(pq)
        if d > dist[v]:
            continue
        for u, weight in edges[v]:
            nd = d + weight
            if dist[u] > nd:
                dist[u] = nd
                heappush(pq, (nd, u))
    return dist

N, M = map(int, input().split())
G = [[] for _ in range(N+1)]
for i in range(2, N+1):
    G[i].append((i - 1, 0))
for _ in range(M):
    L, R, C = map(int, input().split())
    G[L].append((R, C))
dist = dijkstra(G, N+1, 1)
print(dist[N] if dist[N] < INF else -1)
