import sys
from heapq import heappop, heappush


def dijkstra(s, t, links):
    q = [(0, s)]
    visited = set()
    while q:
        cost, v = heappop(q)
        if v in visited:
            continue
        if v == t:
            return cost
        visited.add(v)
        for u, c in links[v]:
            if u in visited:
                continue
            heappush(q, (cost + c, u))
    return -1


n, m = list(map(int, input().split()))
links = [set() for _ in range(n)]
for v in range(n - 1):
    links[v + 1].add((v, 0))
for line in sys.stdin:
    l, r, c = map(int, line.split())
    links[l - 1].add((r - 1, c))
print(dijkstra(0, n - 1, links))
