import sys
input=sys.stdin.readline
import heapq

def dijkstra(Route,v,start):
    Dist=[float('inf')]*v
    Dist[start]=0
    Visited=[False]*v
    hq=[(0,start)]
    while hq:
        dist,fr=heapq.heappop(hq)
        Visited[fr]=True
        for to,cost in Route[fr]:
            if (not Visited[to]) and Dist[to]>dist+cost:
                Dist[to]=dist+cost
                heapq.heappush(hq,(Dist[to],to))
    return Dist

def main():
    n,m=map(int,input().split())
    Edges=[[] for _ in range(n)]
    for i in range(n-1):
        Edges[i+1].append((i,0))
    for _ in range(m):
        l,r,c=map(int,input().split())
        l-=1; r-=1
        Edges[l].append((r,c))
    Dist=dijkstra(Edges,n,0)
    print(-1 if Dist[-1]==float('inf') else Dist[-1])
    
if __name__=='__main__':
    main()