import numpy as np
import heapq

INF=10**12
def daik(s,g,d):
    used=np.array([])
    heap=[]
    table=np.array([INF for i in range(N)])
    table[s]=0
    a=s
    used=np.append(used,a)
    for i in range(N):
        if i!=a and not(i in used):
            cost=d[a,i] if a<=i else d[i,a]
            if cost!=INF:
                table[i]=min(table[i],table[a]+cost)
                heapq.heappush(heap,(table[i],i))
    while heap:
        q=heapq.heappop(heap)
        a=q[1]
        used=np.append(used,a)
        for i in range(N):
            if i!=a and not(i in used):
                cost=d[a,i] if a<=i else d[i,a]
                if cost!=INF:
                    table[i]=min(table[i],table[a]+cost)
                    heapq.heappush(heap,(table[i],i))
    return table[g]


N,M=map(int,input().split())
LRC=[]
for i in range(M):
    L,R,C=map(int,input().split())
    LRC.append([L-1,R-1,C])
LRC=np.array(LRC)
LRC=LRC[np.argsort(LRC[:,2])]

d=np.array([[INF for j in range(N)] for i in range(N)])
for i in range(N):
    d[i,i]=0
l=np.array([i+1 for i in range(N)])
l[-1]=N
for m in range(M):
    L,R,C=LRC[m,0],LRC[m,1],LRC[m,2]
    for i in range(L,R+1):
        if l[i]<N:
            d[i,l[i]:R+1]=C
            l[i]=R+1

ans=daik(0,N-1,d)
if ans==INF:
    print(-1)
else:
    print(ans)