import sys
input = sys.stdin.readline
from heapq import *

def dijkstra():
    dist = [10**18]*N
    dist[0] = 0
    pq = []
    heappush(pq, (0, 0))
    
    while pq:
        d, v = heappop(pq)
        
        if dist[v]<d:
            continue
        
        for nv, w in G[v]:
            if dist[nv]>dist[v]+w:
                dist[nv] = dist[v]+w
                heappush(pq, (dist[nv], nv))
    
    return dist

N, M = map(int, input().split())
G = [[] for _ in range(N)]

for i in range(1, N):
    G[i].append((i-1, 0))
    
for _ in range(M):
    L, R, C = map(int, input().split())
    G[L-1].append((R-1, C))

ans = dijkstra()[-1]

if ans==10**18:
    print(-1)
else:
    print(ans)