from collections import defaultdict
from heapq import heappop, heappush

n, m = map(int, raw_input().split())
graph = {}
for _ in range(m):
    l, r, c = map(int, raw_input().split())
    for s in range(l, r + 1):
        for e in range(s + 1, r + 1):
            if s not in graph:
                graph[s] = {e: c}
            elif e not in graph[s]:
                graph[s][e] = c
            else:
                graph[s][e] = min(graph[s][e], c)

start = 1
dist = defaultdict(lambda: float('inf'))
dist[start] = 0
prev = defaultdict(lambda: None)
queue = []
heappush(queue, (dist[start], start))

while queue:
    dist_u, u = heappop(queue)
    if dist[u] < dist_u:
        continue
    if u not in graph:
        break
    for v, weight in graph[u].items():
        alt = dist_u + weight
        if dist[v] > alt:
            dist[v] = alt
            prev[v] = u
            heappush(queue, (alt, v))

if dist[n] == float('inf'):
    print -1
else:
    print dist[n]