from heapq import heappop, heappush

n, m = map(int, input().split())

g = [[10**10 for _ in range(n)] for __ in range(n)]

for _ in range(m):
    l, r, c = map(int, input().split())
    g[l-1][r-1] = min(g[l-1][r-1], c)

for i in range(1, n):
    g[i][i-1] = 0


d = [10**13] * n
d[0] = 0
q = [(0, 0)]
while q:
    dist_u, u = heappop(q)
    if d[u] < dist_u:
        continue
    for v, c in enumerate(g[u]):
        if d[v] > dist_u + c:
            d[v] = dist_u + c
            heappush(q, (d[v], v))


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