#D
import math
N, M = map(int, input().split())
inf = 10 ** 10
route_list = [[inf for i in range(N)] for i in range(N)]
for i in range(M):
    L, R, C = map(int, input().split())
    for i in range(L, R):
        for j in range(i, R):
            route_list[i-1][j] = min(route_list[i-1][j], C)

def dijkstra(s,n,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
                v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

d_ret = dijkstra(0, N, route_list)
res = d_ret[-1]
if res == inf:
    print("-1")
else:
    print(res)