N,M = map(int,input().split(' '))
tree_list = [[] for _ in range(N) ]
for _ in range(M):
    L,R,C = map(int,input().split(' '))
    tree_list[R-1].append([C,L-1])
inf = float('inf')
dp = [inf] * N
dp[N-1] = 0
current_num = -1
flag = False
if len(tree_list[N-1]) > 0: 
    for i in reversed(range(N)):
        if dp[i] == inf:
            flag = True
            break
        current_start_paths = tree_list[i]
        if len(current_start_paths) > 0:
            current_start_paths.sort()
            for path in current_start_paths:
                if dp[path[1]] > dp[i] + path[0]:
                    for j in range(path[1],i):
                        if (dp[i] + path[0]) < dp[j]:
                            dp[j] = dp[i] + path[0]
                        else:
                            break
    if dp[0] == inf or flag:
        print(-1)
    else:
        print(dp[0])
else:
    print(-1)