import heapq
n, m = map(int, input().split())
INF = float('inf')


def dijkstra(s, n, edges):
    d = [INF] * n
    d[s] = 0
    pq = [(0, s)]
    while len(pq) != 0:
        c, v = heapq.heappop(pq)
        if d[v] < c:
            continue
        for v2nvc, nv in edges[v]:
            if c + v2nvc < d[nv]:
                d[nv] = c + v2nvc
                heapq.heappush(pq, (d[nv], nv))
    return d


edges = [[] for _ in range(n)]
for _ in range(m):
    l, r, c = map(int, input().split())
    l -= 1
    r -= 1
    edges[l].append((c, r))
for i in range(n - 1):
    edges[i + 1].append((0, i))
d = dijkstra(0, n, edges)
if d[-1] == INF:
    print(-1)
else:
    print(d[-1])
