import heapq

n,m = map(int, input().split())
to= [list() for _ in range(n)]
for i in range(m):
    l,r,c = map(int, input().split())
    l-=1
    r-=1
    to[l].append((r,c))

for i in range(1,n):
    to[i].append((i-1,0))

q = []
INF = 1001001001001001
d = [INF]*n
d[0]=0
heapq.heappush(q,(0,0))
while q:
    cost,u = heapq.heappop(q)
    if d[u]<cost:
        continue
    for v,c in to[u]:
        if d[v]>d[u]+c:
            d[v]=d[u]+c
            heapq.heappush(q,(d[v],v))

if d[-1]==INF:
    print(-1)
else:
    print(d[-1])
        

