import heapq
N,M=map(int,input().split())
G=[dict() for i in range(N)]
for i in range(M):
    l,r,c=map(int,input().split())
    G[l-1][r-1]=c
for i in range(1,N):
    G[i][i-1]=0
def dijkstra(adj, st):
    dist=[10**15 for i in range(N)]
    dist[st]=0
    q=[]
    heapq.heappush(q,(0,st))
    while (len(q)!=0):
        prc,src=heapq.heappop(q)
        if dist[src]<prc:
            continue
        for dest in adj[src]:
            cost=adj[src][dest]
            if dist[dest]>dist[src]+cost:
                dist[dest]=dist[src]+cost
                heapq.heappush(q,(dist[dest],dest))                
    return dist
ans=dijkstra(G,0)[-1]
if ans==10**15:
    ans=-1
print(ans)
