
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
 
import heapq
def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d


n, m = map(int,input().split())

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(m):
    l, r, c = map(int,input().split())
    edge[l-1].append([c,r-1])
    for j in range(r-l):
        edge[r-1-j].append([0,r-2-j]) 
ans = dijkstra_heap(0)[n-1]
if ans > 10**14:
    print(-1)
else:
    print(ans)