import heapq
def dijkstra_heap(s,edge,n):
    d = [float("inf")] * n
    used = [True] * n
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v],e[1]))
    return d

n,m = map(int,input().split())
graph = [[] for _ in range(n)]
for i in range(1,n):
    graph[i].append((0,i-1))
for i in range(m):
    l,r,c = map(int,input().split())
    graph[l-1].append((c,r-1))
ans = dijkstra_heap(0,graph,n)[-1]
if ans == float("inf"):
    print(-1)
else:
    print(ans)