n, m = map(int, input().split())
inf = 10 ** 15
edges = [[] for _ in range(n)]
for _ in range(m):
    l, r, c = map(int, input().split())
    edges[l-1].append((r-1, c))
for i in range(n-1):
    edges[i+1].append((i, 0))

from heapq import heappop, heappush
d = [inf for _ in range(n)]
def dijkstra(s):
    que = []
    d[s] = 0
    heappush(que, (0, s))

    while len(que):
        dist, node = heappop(que)

        if d[node] < dist:
            continue
        for to, cost in edges[node]:
            if d[to] > dist + cost:
                d[to] = dist + cost
                heappush(que, (d[to], to))

dijkstra(0)

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