import sys
input = sys.stdin.readline
N,M = map(int,input().split())
LRC = [tuple(map(int,input().split())) for i in range(M)]

es = [[] for _ in range(N)]
for l,r,c in LRC:
    l,r = l-1,r-1
    es[l].append((r,c))
for i in range(1,N):
    es[i].append((i-1,0))

import heapq
hq = [(0,0)]
INF = float('inf')
cost = [INF] * N
cost[0] = 0
while hq:
    d,v = heapq.heappop(hq)
    for to,c in es[v]:
        if cost[to] <= d+c: continue
        cost[to] = d+c
        heapq.heappush(hq, (d+c,to))

print(-1 if cost[-1]==INF else cost[-1])