import sys
from heapq import heappush,heappop,heapify
read=sys.stdin.readline
INF=10**30

def dijkstra(G,s,n):
    que=[(0,s)]
    dist=[INF]*n
    dist[s]=0
    while que:
        mincost,u=heappop(que)
        if(mincost>dist[u]):
            continue
        for c,v in G[u]:
            if(dist[u]+c<dist[v]):
                dist[v]=dist[u]+c
                heappush(que,(dist[v],v))
    return dist

N,M=map(int,read().split())

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