from operator import itemgetter
 
list1 = [[1,5,3], [6,4,8], [9,11,2]]
list1.sort(key=itemgetter(1))


N, M = map(int, input().split())
LRC = []

D = [float('Inf')] * (N+1)
D[1] = 0

for m in range(M):
    l, r, c = map(int, input().split())
    LRC.append([l, r, c])

LRC.sort(key=itemgetter(1))

for m in range(M):
    l, r, c = LRC[m][0], LRC[m][1], LRC[m][2]
    for a in range(l+1, r+1):
        if D[a] > D[l] + c:
            D[a] = D[l] + c

if D[N] < float('Inf'):
    print(D[N])
else:
    print(-1)
    