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

graph = [[] for _ in range(N)]

LRC.sort(key=lambda x: x[1])

for i, (Li, Ri, Ci) in enumerate(LRC):
    graph[Li - 1].append((Ri, Ci))

for i, (Li, Ri, Ci) in enumerate(LRC):
    for idx in range(Ri - Li):
        if len(graph[(Ri - idx - 1) - 1]) > 0:
            if graph[(Ri - idx - 1) - 1][-1][0] > Ri:
                graph[Ri - 1].append(((Ri - idx - 1), 0))

# for i in range(N):
#     print("#", graph[i])
            
import heapq

inf = 10 ** 18
d = [inf] * N

q = [(0, 1)] # cost, pos
while len(q) > 0:
    cost, src = heapq.heappop(q)
    for dst, c_dst in graph[src - 1]:
        if cost + c_dst < d[dst - 1]:
            d[dst - 1] = cost + c_dst
            heapq.heappush(q, (cost + c_dst, dst))

if d[N - 1] == inf:
    print(-1)
else:
    print(d[N - 1])