import numpy as np
from operator import itemgetter

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

D = np.array([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))

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

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