import heapq
INF=10**9
n,m=map(int,input().split())
edge=[[] for _ in range(n)]
d=[INF for _ in range(n)]
d[0]=0

for i in range(m):
    l,r,c=map(int,input().split())
    for j in range(l-1,r):
        for k in range(j+1,r):
            edge[j].append([c,k])
            edge[k].append([c,j])

q=[]
heapq.heapify(q)
heapq.heappush(q, [0,0])

def dijkstra():
    while(len(q)!=0):
        cs=heapq.heappop(q)
        cost=cs[0]
        start=cs[1]

        if(d[start] < cost):
            continue

        e=edge[start]
        for ei in e:
            if(d[ei[1]] > d[start]+ei[0]):
                heapq.heappush(q, [d[start]+ei[0],ei[1]])
                d[ei[1]] = d[start]+ei[0]

dijkstra()
print(d[len(d)-1] if d[len(d)-1]!=INF else -1)
