CM = 1000000000 * 100000 * 10

N,M = map(int, input().strip().split(" "))
LRC = []
for i in range(M):
    LRC.append(list(map(int, input().strip().split(" "))))
LRC.sort(key = lambda x:x[0])
P = [CM] * N
P[0] = 0
while True:
    chk = False
    for l in LRC:
        for i in range(l[0], l[1]):
            if P[l[0]-1] + l[2] < P[i]:
                P[i] = P[l[0]-1] + l[2]
                chk = True
    if not chk:
        break
if P[-1] == CM:
    print(-1)
else:
    print(P[-1])
