from heapq import heappush,heappop
n,m=map(int,input().split())
lrc=[list(map(int,input().split())) for i in range(m)]
data=[[] for i in range(n+1)]
for i in range(2,n+1):
    data[i].append([i-1,0])
for u in lrc:
    l,r,c=u
    data[l].append([r,c])
lst=[]
flag=[-1]*(n+1)
flag[1]=0
for u in data[1]:
    heappush(lst,[u[1],u[0]])
while lst:
    c,r=heappop(lst)
    if r==n:
        print(c)
        break
    if flag[r]==-1:
        flag[r]=c
        for u in data[r]:
            if flag[u[0]]==-1:
                heappush(lst,[c+u[1],u[0]])
else:
    print(-1)