from heapq import heappop, heappush

n, m = map(int, input().split())
graph = [list() for _ in range(n)]

for i in range(1, n):
    graph[i].append((i-1, 0))

for _ in range(m):
    f, t, c = map(int, input().split())
    f -= 1; t -= 1
    graph[f].append((t, c))

INF = float("inf")
s = 0
d = [0] + [INF] * (n-1)
q = []
heappush(q, (0, s))

while q:
    dist, v = heappop(q)
    if d[v] < dist: continue
    for nv, cost in graph[v]:
        if d[nv] > d[v] + cost:
            d[nv] = d[v] + cost
            heappush(q, (d[nv], nv))

print(-1 if d[n-1] == INF else d[n-1])
