from collections import defaultdict
from heapq import heappop, heappush
import sys
input = sys.stdin.readline


def dijkstra1(V, n, inf, source):
    # O(ElogV)

    dist = [inf] * (n+1)
    dist[source] = 0
    q = [(0, source)]

    while q:
        cost, u = heappop(q)
        if dist[u] < cost:
            continue
        for c, v in V[u]:
            if dist[v] > dist[u] + c:
                dist[v] = dist[u] + c
                heappush(q, (dist[v], v))

    return dist


def solve():
    N, M = map(int, input().split())
    INF = 10**20
    l = []
    V = defaultdict(list)

    for _ in range(M):
        L, R, C = map(int, input().split())
        V[L].append((C, R))

    for i in range(1, N):
        V[i+1].append((0, i))

    dj = dijkstra1(V, N, INF, 1)
    print(dj[N] if dj[N]!=INF else -1)


if __name__ == "__main__":
    solve()
