import sys
def input():
    return sys.stdin.readline()[:-1]

N,M = map(int,input().split(' '))
K = [None]*M
for i in range(M):
    K[i] = list(map(int,input().split(' ')))

MAP = [None]*N
for i in range(N):
    MAP[i] = [None]*N

for i in range(M):
    l,r,c = K[i]
    for j in range(l-1,r):
        for k in range(j+1,r):
            m = MAP[j][k]
            if m==None:
                MAP[j][k] = c
            else:
                if c<m:
                    MAP[j][k] = c

shortest = [None]*N
shortest[0] = 0

#今何番目nodeか,N,nodeが持ってる辺,MAP
def bfs(i,N,l,shortest):
    #そこまでの最短ルート
    cnt = shortest[i]
    if cnt==None:
        print(-1)
        exit()
    #当該のnodeからの距離
    for i in range(i,N):
        m = l[i]
        if m==None:
            continue
        new_one = shortest[i]
        if not new_one==None:
            #m+cntは1からの距離
            shortest[i] = min(new_one,m+cnt)
        else:
            shortest[i] = m+cnt
    return shortest

for i in range(N):
    l = MAP[i]
    shortest = bfs(i,N,l,shortest)
if shortest[-1]==None:
    print(-1)
else:
    print(shortest[-1])