import sys
from heapq import heappop as hpp, heappush as hp
inf = 10**20
def dijkstra(N, s, Edge):
    dist = [inf] * N
    Q = [(0, s)]
    decided = set()
    for _ in range(N):
        while True:
            dn, vn = hpp(Q)
            if vn not in decided:
                decided.add(vn)
                dist[vn] = dn
                break
        for vf, df in Edge[vn]:
            if vf not in decided:
                hp(Q, (dn + df, vf))
    return dist

readline = sys.stdin.readline
N, M = map(int, readline().split())

Edge = [[] for _ in range(N)]
for i in range(M):
    L, R, C = map(int, readline().split())
    L -= 1
    R -= 1
    Edge[L].append((R, C))

for i in range(1, N):
    Edge[i].append((i-1, 0))
for i in range(1, N):
    Edge[0].append((i, inf))
dist = dijkstra(N, 0, Edge)
if dist[N-1] == inf:
    ans = -1
else:
    ans = dist[N-1]
print(ans)
